2015-11-16 39 views
1

我正在爲iOS和Apple手錶編寫應用程序,並且需要在Apple Watch和iPhone之間同步數據。同步從Apple Watch到Swift的數據

我這樣做是從iPhone發送DAT像這裏提到蘋果手錶:http://telliott.io/2015/08/11/how-to-communicate-between-ios-and-watchos2.html

的另一種方式,如果我改變我的手錶上的應用程序數據和更新後的數據發送到我的iPhone有一個奇怪的警告,如果收到消息的ViewController被打開。當它被關閉,我從我的手錶發送更新的數據有我的控制檯上沒有任何警告,如果我打開視圖控制器中的數據被更新:

2015-11-16 11:28:19.057 GeoSocialRecommender[286:11448] This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release. 
Stack:(
0 CoreFoundation      0x0000000182410f60 <redacted> + 148 
1 libobjc.A.dylib      0x0000000196fc3f80 objc_exception_throw + 56 
2 CoreFoundation      0x0000000182410e90 <redacted> + 0 
3 Foundation       0x000000018342f2d8 <redacted> + 88 
4 Foundation       0x00000001832b5a1c <redacted> + 56 
5 Foundation       0x00000001832b15dc <redacted> + 260 
6 UIKit        0x0000000187aab8c4 <redacted> + 64 
7 UIKit        0x0000000187aac3dc <redacted> + 244 
8 UIKit        0x000000018820b1e4 <redacted> + 268 
9 UIKit        0x0000000187cb0f10 <redacted> + 176 
10 UIKit        0x000000018799f7ac <redacted> + 644 
11 QuartzCore       0x000000018719eb58 <redacted> + 148 
12 QuartzCore       0x0000000187199764 <redacted> + 292 
13 QuartzCore       0x0000000187199624 <redacted> + 32 
14 QuartzCore       0x0000000187198cc0 <redacted> + 252 
15 QuartzCore       0x0000000187198a08 <redacted> + 512 
16 QuartzCore       0x00000001871c7b0c <redacted> + 236 
17 libsystem_pthread.dylib    0x00000001979f61e0 <redacted> + 584 
18 libsystem_pthread.dylib    0x00000001979f5d58 <redacted> + 136 
19 libsystem_pthread.dylib    0x00000001979f553c pthread_mutex_lock + 0 
20 libsystem_pthread.dylib    0x00000001979f5020 start_wqthread + 4 
) 

任何人都可以幫我這個怪異的警告?

這是我得到的消息的方法

func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]){ 
    if(WCSession.isSupported()){ 
     self.prefs = Utils().importDataFromSession(prefs, applicationContext: applicationContext) 
     initializeGUI(true) 

    } 
} 

回答

1

的WCSession頭說:

/** ----------------------------- WCSessionDelegate ----------------------------- 
* The session calls the delegate methods when content is received and session 
* state changes. All delegate methods will be called on the same queue. The 
* delegate queue is a non-main serial queue. It is the client's responsibility 
* to dispatch to another queue if neccessary. 
*/ 

所以,如果你想更新你需要確保代碼在運行UI應用程序的主線程;因此請對您的代碼進行以下更改並且警告將消失:

func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]){ 
    if (WCSession.isSupported()) { 
     self.prefs = Utils().importDataFromSession(prefs, applicationContext: applicationContext) 
     dispatch_async(dispatch_get_main_queue(), { 
      initializeGUI(true) 
     }) 
    } 
} 
+0

謝謝!這解決了我的問題 – hannes

相關問題