Cov txheej txheem:

Kev sib thooj Duab Sib Koom IOS App: 6 Kauj Ruam
Kev sib thooj Duab Sib Koom IOS App: 6 Kauj Ruam

Video: Kev sib thooj Duab Sib Koom IOS App: 6 Kauj Ruam

Video: Kev sib thooj Duab Sib Koom IOS App: 6 Kauj Ruam
Video: Jack GV - Kuv Thov Txim Ft. Vicky Yang (Official Audio) 2024, Hlis ntuj nqeg
Anonim

Hauv cov lus qhia no peb yuav tsim iOS app nrog Swift uas tso cai rau koj qhia cov duab nrog txhua tus neeg nyob ze, tsis tas yuav siv lub cuab yeej txuas ua ke.

Peb yuav siv Chirp Txuas xa cov ntaub ntawv siv suab, thiab Firebase khaws cov duab hauv huab.

Kev xa cov ntaub ntawv nrog lub suab tsim qhov kev paub tshwj xeeb uas cov ntaub ntawv tuaj yeem tshaj tawm rau txhua tus neeg hauv thaj tsam hnov lus.

Kauj Ruam 1: Nruab Qhov Yuav Tsum Tau Ua

Xcode

Nruab los ntawm App Store.

CocoaPods

sudo lub pov haum nruab cocoapods

Chirp Txuas iOS SDK

Sau npe ntawm admin.chirp.io

Kauj ruam 2: Teeb Project

1. Tsim qhov project Xcode.

2. Kos npe rau hauv Firebase thiab tsim txoj haujlwm tshiab.

Pab kom Firestore los ntawm txhaj rau ntu Database thiab xaiv Cloud Firestore. Nyem rau hauv Kev Ua Haujlwm kuj tseem tuaj yeem pab ua haujlwm huab.

3. Khiav los ntawm teeb tsa koj li iOS app ntawm nplooj ntawv Txheej txheem cej luam

Koj yuav xav tau Cov Ntawv Qhia Tus Kheej los ntawm General Tab hauv koj li Xcode Project Settings. Thaum lub Podfile tau tsim los koj yuav xav tau ntxiv cov kev vam khom hauv qab no, ua ntej yuav nruab pod.

# Pods rau qhov project

pod 'Firebase/Core' pod 'Firebase/Firestore' pod 'Firebase/Cia'

4. Rub tawm qhov tseeb Chirp Txuas iOS SDK los ntawm admin.chirp.io/downloads

5. Ua raws cov kauj ruam ntawm developers.chirp.io los koom ua ke Chirp Txuas rau Xcode.

Mus rau Pib Pib / iOS. Tom qab ntawv nqes mus thiab ua raws Swift teeb tsa cov lus qhia qhov no yuav koom nrog kev nkag mus rau lub moj khaum thiab tsim txoj kab txuas txuas.

Tam sim no teeb tsa tiav, peb tuaj yeem pib sau qee qhov chaws! Nws yog lub tswv yim zoo los tshuaj xyuas koj txoj haujlwm tsim ntawm txhua theem hauv kev teeb tsa.

Kauj ruam 3: Sau IOS Code

1. Ntshuam Firebase rau hauv koj tus ViewController thiab txuas ntxiv NSData kom suav nrog hexString txuas ntxiv, yog li peb tuaj yeem hloov Chirp Txuas cov nyiaj them poob haujlwm rau txoj hlua hexadecimal. (Chirp Txuas yuav muaj nyob thoob plaws ntiaj teb ua tsaug rau qhov txuas txuas lub taub hau).

ntshuam UIKit

ntshuam Firebase

Cov ntaub ntawv txuas ntxiv {

var hexString: Txoj hlua {xa daim duab qhia chaw {Txoj hlua (hom ntawv: "%02x", UInt8 ($ 0)))}.joined ()}}

2. Ntxiv ImagePicker cov neeg sawv cev rau koj tus ViewController, thiab tshaj tawm ChirpConnect qhov sib txawv hu ua txuas.

chav ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

var txuas: ChirpConnect? override func viewDidLoad () {super.viewDidLoad ()…

3. Tom qab super.viewDidLoad, pib Chirp Txuas, thiab teeb tsa qhov tau txais rov qab. Hauv qhov tau txais kev hu rov qab peb yuav khaws cov duab los ntawm Firebase siv cov nyiaj tau txais thiab hloov kho ImageView. Koj tuaj yeem tau txais koj li APP_KEY thiab APP_SECRET los ntawm admin.chirp.io.

txuas = ChirpConnect (appKey: APP_KEY, thiabSecret: APP_SECRET) yog tias cia txuas = txuas {connect.getLicenceString {(daim ntawv tso cai: hlua?, yuam kev: Yuam kev?) hauv yog yuam kev == nil {yog tias tso cai = tso cai {txuas.setLicenceString (daim ntawv tso cai) txuas.start () txuas.receivedBlock = {(cov ntaub ntawv: Cov ntaub ntawv?) -> () hauv yog tias cia cov ntaub ntawv = cov ntaub ntawv {luam tawm (Txoj hlua (hom ntawv: "Tau txais cov ntaub ntawv: %@", data.hexString)) cia cov ntawv = Storage.storage (). Reference (). Child (data.hexString) file.getData (maxSize: 1 * 1024 * 2048) {imageData, yuam kev yog tias cia yuam kev = yuam kev {print ("Yuam kev: %@", yuam kev.localizedDescription)} else {self.imageView.image = UIImage (data: imageData!)}}} else {print ("Decode failed"); }}}}

4. Tam sim no ntxiv cov cai kom xa cov ntaub ntawv duab ib zaug nws tau raug xaiv hauv UI.

func imagePickerController (_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any])

{cia imageData = info [UIImagePickerControllerOriginalImage] li? UIImage cia cov ntaub ntawv: Cov ntaub ntawv = UIImageJPEGRepresentation (imageData !, 0.1)! self.imageView.image = imageData cia metadata = StorageMetadata () metadata.contentType = "duab/jpeg" yog tias cia txuas = txuas {txuas qhov tseem ceeb: Cov ntaub ntawv = txuas.randomPayload (nrogLength: 8) Firestore.firestore (). sau (". uploads "). addDocument (cov ntaub ntawv: [" qhov tseem ceeb ": key.hexString," timestamp ": FieldValue.serverTimestamp ()]) {yuam kev hauv yog tias ua yuam kev = yuam kev {luam tawm (error.localizedDescription)}} Storage.storage ().reference (). tus menyuam (key.hexString).putData (cov ntaub ntawv, metadata: metadata) {(metadata, yuam kev) hauv yog tias cia yuam kev = yuam kev {luam tawm (error.localizedDescription)} lwm yam {connect.send (qhov tseem ceeb)}} } self.dismiss (animated: tseeb, tiav: nil)}

Nco tseg: Koj yuav tsum tau ntxiv Tus Kheej - Cov Tsev Qiv Ntawv Siv Cov Lus Qhia, Tsis Pub Leej Twg Paub - Kev Siv Lub Tsev Qiv Ntawv Qhia thiab Tsis Pub Leej Twg Paub - Microphone Siv Cov Lus Qhia nqe lus rau koj Info.plist kom tso cai siv lub Koob Yees Duab, Lub Tsev Qiv Duab thiab Microphone.

Kauj Ruam 4: Tsim Tus Neeg Siv Kev Sib Tham

Tsim Tus Neeg Siv Khoom Siv
Tsim Tus Neeg Siv Khoom Siv

Tam sim no mus rau Main.storyboard cov ntaub ntawv los tsim UI.

1. Luag hla ib qho ImageView thiab ob lub khawm mus rau Storyboard los ntawm Lub Tsev Qiv Ntawv Vaj Huam Sib Luag nyob hauv qab txoj cai kaum.

2. Rau txhua lub khawm ntxiv qhov siab txwv txog 75px los ntawm kev xaiv cov khoom siv thiab nyem rau qhov Add New Constraints khawm (ib qho uas zoo li Star Wars khi sib ntaus), thiab tom qab ntawd nkag mus rau qhov siab thiab nias Enter.

3. Xaiv tag nrho peb ntu thiab muab tso rau hauv pawg saib los ntawm txhaj rau Embed In Stack khawm.

4. Tam sim no qhib Tus Pabcuam Editor, thiab nias CTRL thiab rub los ntawm txhua feem mus rau ViewController code, los tsim Outlets rau txhua feem.

@IBOutlet var imageView: UIImageView!

@IBOutlet var openLibraryButton: UIButton! @IBOutlet var openCameraButton: UIButton!

5. Tam sim no CTRL thiab luag los ntawm ob lub nyees khawm los tsim qhov Action los qhib lub koob yees duab/tsev qiv ntawv UI's.

6. Hauv qhov Qhib Qhib Qhib, ntxiv cov cai hauv qab no

@IBAction func openLibrary (_ sender: Txhua) {

cia imagePicker = UIImagePickerController () imagePicker.delegate = tus kheej; imagePicker.sourceType =.photoLibrary self.present (imagePicker, animated: tseeb, tiav: nil)}

7. Hauv Qhib Lub Koob Yees Duab ua

@IBAction func openCamera (_ tus xa: Txhua) {

cia imagePicker = UIImagePickerController () imagePicker.delegate = tus kheej imagePicker.sourceType =.camera; self.present (imagePicker, ua yeeb yaj kiab: muaj tseeb, ua tiav: nil)}

Kauj Ruam 5: Sau Huab Huab

Raws li cov duab tsis tas yuav khaws cia hauv huab mus ib txhis, peb tuaj yeem sau Huab Cua Ua Haujlwm los ua kev ntxuav. Qhov no tuaj yeem ua rau muaj kev ua haujlwm HTTP txhua teev los ntawm kev pabcuam cron xws li cron-job.org.

Ua ntej tshaj plaws peb yuav tsum teeb tsa firebase-cov cuab yeej

npm nruab -g firebase -tools

Tom qab ntawd los ntawm txoj haujlwm lub hauv paus phau ntawv teev npe

firebase pib

Xaiv cov haujlwm los ntawm kab hais kom ua rau pib ua haujlwm huab. Koj tseem tuaj yeem pab tua hluav taws yog tias koj xav tau kuj tseem xav teeb tsa Firestore.

Tom qab ntawd qhib cov haujlwm/index.js thiab ntxiv cov cai hauv qab no. Nco ntsoov hloov

rau koj qhov Firebase project id.

const functions = xav tau ('firebase-functions');

const admin = xav tau ('firebase-admin'); admin.initializeApp () export.cleanup = functions.https.onRequest ((thov, teb) => {admin.firestore ().collection ('uploads'). where ('timestamp', '{snapshot.forEach (doc = > {admin.storage ().bucket ('gs: //.appspot.com').file (doc.data ().key).delete () doc.ref.delete ()}) rov teb.status (200).send ('OK')}).catch (yuam kev => response.status (500). Xa (yuam kev))});

Kev xa tawm huab ua haujlwm yog yooj yim li khiav cov lus txib no.

firebase deploy

Tom qab ntawd ntawm cron-job.org tsim txoj haujlwm los ua kom muaj qhov kawg no txhua teev. Qhov kawg yuav yog ib yam zoo li

us-central1-project_id.cloudfunctions.net/cleanup

Kauj ruam 6: Khiav lub App

Khiav lub app ntawm tus simulation lossis ntaus ntawv iOS, thiab pib sib koom duab!

Pom zoo: