2017-07-10 81 views
0

我試圖在模擬器上運行我的項目,但iOS端未激活,只有Watch端設法激活。WatchConnectivity在模擬器上運行時未在iOS端激活

這裏是我的ScoresInterfaceController.swift(觀看側)

import WatchConnectivity  

class ScoresInterfaceController: WKInterfaceController, WCSessionDelegate { 

    // Used to send information to the iOS app 
    var applicationDict = [String: Int]() 

    // Starts a session to communicate with the iOS app 
    var session: WCSession! 

    // For WCSession 
    override init() { 
     super.init() 

     if(WCSession.isSupported()) { 
      session = WCSession.default() 
      session.delegate = self 
      session.activate() 
     } 
    } 

    func session(_ session: WCSession, 
      activationDidCompleteWith activationState: WCSessionActivationState, 
      error: Error?) {} 

這裏是我的ScoreViewController.swift(iOS版側)

import WatchConnectivity  

class ScoreViewController: UIViewController, WCSessionDelegate {  

    // Starts a session to communicate with the Watch app 
    var session: WCSession! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     if(WCSession.isSupported()) { 
      session = WCSession.default() 
      session.delegate = self 
      session.activate() //Not activating when run on Simulator  
     } 
    } 

    // For WCSession 

    /** Called when the session has completed activation. If session state is WCSessionActivationStateNotActivated there will be an error with more details. */ 
    @available(iOS 9.3, *) 
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {} 

    // Receives data from Watch app 
    @nonobjc func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {} 

    func sessionDidBecomeInactive(_ session: WCSession) {} 

    func sessionDidDeactivate(_ session: WCSession) { 
     WCSession.default().activate() 
    } 
} 

以下是錯誤消息:

enter image description here

我按照這個教程,但我無法弄清楚什麼問題是:

http://kristina.io/watchos-2-how-to-communicate-between-devices-using-watch-connectivity/

回答

0

改變了我的ScoreViewController會話的定義與此:

@nonobjc func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {} 

這樣:

func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) 
相關問題