The main repo for the O3 wallet on iOS.git
下載 OzoneWalletIOS 項目到本地:github
下載 OzoneWalletIOS 項目swift
用 Xcode 打開項目並運行:api
運行出錯緩存
缺乏文件網絡
運行出錯,發現缺乏文件。打開項目目錄,發現有這兩個文件 Cartfile、Cartfile.resolved:app
Cartfile 文件ui
該項目是用 Carthage 管理 iOS 依賴庫的,安裝使用方法看這裏,若是安裝不成功請下載 Releases 版本進行安裝。spa
打開終端,cd 到該項目目錄,運行以下命令:日誌
$ carthage update --platform iOS
$ carthage update –platform iOS 命令
缺乏的文件已下載完成
命令運行成功以後,再次運行項目:
info.plist 文件錯誤
發現 info.plist 文件讀取錯誤,沒法打開。個人解決方法是,新建一個 Project,而後把新工程裏的 info.plist 文件拷貝到該項目裏替換掉,而後再次運行:
Reason image not found 錯誤
在 Finder 裏前往文件夾 ~/Library/Developer/Xcode/DerivedData ,刪除緩存目錄下的文件 :
刪除緩存目錄下的文件
再次運行,發現仍是一樣的錯誤,後來發現新加的一個庫文件 AutoInsetter 沒有加進去:
*** Building scheme "AutoInsetter" in AutoInsetter.xcworkspace
添加庫文件 1
添加庫文件 2
添加好後再次運行:
「networkKey」 出錯
這個錯誤不知道怎麼分析,全局搜索了一下「 networkKey」,發現是跟用戶數據有關,後來總體看了一下項目,而後把項目的 Main Interface 改了一下:
修改 Main Interface
再一次運行:
Info.plist 文件缺乏 Fabric 字段 1
Info.plist 文件缺乏 Fabric 字段 2
開啓 Background Modes:
開啓 Background Modes
向 Info.plist 文件添加 Fabric 字段,包含一個 String 類型的 APIKey 和一個 Array 類型的 Kits:
QQ20180131-144207@2x.png
好了,再次運行:
模擬器運行界面
終於運行成功了!!!/(ㄒoㄒ)/~~
Channel.framework 大概是跟推送通知有關的庫:
func setupChannel() { //O3 Development on Channel app_gUHDmimXT8oXRSpJvCxrz5DZvUisko_mliB61uda9iY Channel.setup(withApplicationId: "app_gUHDmimXT8oXRSpJvCxrz5DZvUisko_mliB61uda9iY") }
設置應用的外觀樣式:
func setupApperances() { UIBarButtonItem.appearance().setTitleTextAttributes([ NSAttributedStringKey.font: ThemeManager.barButtonItemFont, NSAttributedStringKey.foregroundColor: UserDefaultsManager.theme.primaryColor], for: .normal) UINavigationBar.appearance().largeTitleTextAttributes = [ NSAttributedStringKey.foregroundColor: UserDefaultsManager.theme.textColor, NSAttributedStringKey.font: UIFont(name: "Avenir-Heavy", size: 32) as Any] }
建立用戶的默認配置:
func registerDefaults() { let userDefaultsDefaults: [String: Any] = [ "networkKey": "main", "usedDefaultSeedKey": false, "selectedThemeKey": Theme.light.rawValue ] UserDefaults.standard.register(defaults: userDefaultsDefaults) }
開啓網絡狀態監測:
let alertController = UIAlertController(title: "Uh oh! There is no internet connection. 😵", message: nil, preferredStyle: .alert) @objc func reachabilityChanged(_ note: Notification) { switch reachability.connection { case .wifi: print("Reachable via WiFi") alertController.dismiss(animated: true, completion: nil) case .cellular: print("Reachable via cellular") alertController.dismiss(animated: true, completion: nil) case .none: print("Network not reachable") UIApplication.shared.keyWindow?.rootViewController?.presentFromEmbedded(alertController, animated: true, completion: nil) } } let reachability = Reachability()! func setupReachability() { NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged(_:)), name: .reachabilityChanged, object: nil) do { try reachability.startNotifier() } catch { print("could not start reachability notifier") } }
檢查本地是否存在錢包,若是存在就將主窗口設置爲登陸到本地錢包的界面:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Fabric.with([Crashlytics.self]) self.registerDefaults() self.setupChannel() self.setupApperances() self.setupReachability() //check if there is an existing wallet in keychain //if so, present LoginToCurrentWalletViewController let walletExists = UserDefaultsManager.o3WalletAddress != nil if walletExists { let login = UIStoryboard(name: "Onboarding", bundle: nil).instantiateViewController(withIdentifier: "LoginToCurrentWalletViewController") if let window = self.window { window.rootViewController = login } } return true }
OnboardingHomeViewController.swift
歡迎留言討論,有錯誤請指出,謝謝!
【聯繫我(QQ:3500229193)或者加入社羣,請戳這裏!】
2018.02.02 第一次更新
2018.02.23 第二次更新
2018.08.07 第三次更新
做者:AlleniCoder
連接:https://www.jianshu.com/p/85a...來源:簡書簡書著做權歸做者全部,任何形式的轉載都請聯繫做者得到受權並註明出處。