2

当手表被停用和快速重新激活(在 1-2 秒的时间跨度内降低和升高)时,WatchConnectivity 似乎无法更新其可达状态。这在我的设备上可靠地发生。

编辑:这是一个错误的演示:https ://youtu.be/hx7VR8IPxT8

这是一份开放雷达报告#23337218

我编写了一个测试项目来为您提供最简单的错误示例。

import UIKit
import WatchConnectivity

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, WCSessionDelegate {

    var window: UIWindow?
    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        session?.delegate = self;
        session?.activateSession()
        return true
    }
    func sessionReachabilityDidChange(session: WCSession) {
        print("Session \(session.reachable ? "reachable" : "not reachable")")
        dispatch_async(dispatch_get_main_queue(),{
            //updates UI
        })
    }
}

和手表扩展

import WatchKit
import WatchConnectivity

class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate {
    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil

    func applicationDidFinishLaunching() {
        // Perform any final initialization of your application.
    }

    func applicationDidBecomeActive() {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        session?.delegate = self;
        session?.activateSession()
    }

    func applicationWillResignActive() {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, etc.
    }

}

当我放下手表时会发生什么:代表在 1-2 秒内调用 sessionReachabilityDidChange 给出正确的状态。

然后,如果我在 sessionReachabilityDidChange 更新后举起手表,则代表会按预期再次被调用。

但是,如果我在 sessionReachabilityDidChange 更新之前提高手表,则代表只被调用一次,反映了不可到达状态并且无法再次调用以反映手表应用程序的正确活动状态。

这是项目的下载https://dl.dropboxusercontent.com/u/2649851/WatchConnectivityTest.zip

编辑:我应该提到这在模拟器上似乎不是问题。

4

0 回答 0