Apple Watch開發總結
今日,特酷吧開發完成了’多識閱讀-可以聽的個性化訂閱工具’Apple Watch的適配,目前正在審核中,下面是開發中的總結
一,identifier標示
執行[self pushControllerWithName:@”Interface Controller1” context:nil];
彈不出頁面,查明是由于需要在WatchKit App的storyboard中設置scene的identifier.
pushControllerWithName需要和這個identifier保持一致。其他一些地方也需要identifier標示
二,Glance interfaces不支持button
Glances 不支持button,添加了Button會報錯
Illegal Configuration: Buttons are not supported in Glance interfaces.
三,Watch App的版本號包括build版本號必須和Host App保持一致
否則會出錯:error: The value of CFBundleShortVersionString in your WatchKit app’s Info.plist (1.0) does not match the value in your companion app’s Info.plist (1.0.5). These values are required to match.
四,Apple Watch的UI布局沒有iOS應用復雜
只能通過Group以及WKInterfaceButton等UI部件的組合,且可以設置布局的參數也比較少:
1,Horizontal方向的Left,Center,Right;
2,Vertical方向的Top,Center,Bottom;
3,UI組件寬高的Size To Fit Content,Relative to Container,Fixed。
五,Apple Watch的ICON尺寸大小
參考: http://www.cocoachina.com/design/20141124/10306.html
六,Watch App和Extension App通信和數據共享
1,使用MMWormhole
內部使用CFNotificationCenterRef。“多識閱讀”在開發中就使用了MMWormhole
2,App Groups
1.通過NSUserDefaults共享數據 為了防止出現數據同步問題,不要忘記調用[shared synchronize]; 2,通過NSFileManager共享數據 NSFileManager在iOS7提供了containerURLForSecurityApplicationGroupIdentifier方法,可以用來實現extension和
七,在應用和擴展間共享代碼 - Framework
和數據共享類似,extension和containing app很自然地會有一些業務邏輯上可以共用的代碼,這時可以通過iOS8中開放使用的framework實現。
具體參考: http://www.onevcat.com/2014/08/notification-today-widget/
八,Watch App 調試方法
首先在模擬器運行Apple Watch App,在iphone 模擬器中啟動Host App,依次打開Xcode - Debug - Attach to Process 里找到host app 線程,Attach上即可。
九,提交審核須知
提交到iTunes Connect上時,要求iOS App,Extension App以及Apple Watch App都應該有一個Bundle ID,同時配置各自的distribution profile.也就是說發布一個支持Apple Watch的App,至少需要三個Bundle ID。
否則會提示:
error: Embedded binary is not signed with the same certificate as the parent app. Verify the embedded binary target’s code sign settings match the parent app’s.
另外,文案中提到Apple Watch的地方一定不能拼寫錯誤,正確的方式是”Apple Watch”。