2

ウォッチが非アクティブ化され、急速に再アクティブ化されると、WatchConnectivity は到達可能な状態の更新に失敗するようです (1 ~ 2 秒の時間間隔で下げたり上げたりします)。これは、私のデバイスで確実に発生します。

編集: これはバグのデモです: https://youtu.be/hx7VR8IPxT8

これは Open Radar レポート #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.
    }

}

時計を下げるとどうなるか: デリゲートは sessionReachabilityDidChange を 1 ~ 2 秒で呼び出し、正しい状態を示します。

その後、sessionReachabilityDidChange の更新後に監視を開始すると、期待どおりにデリゲートが再度呼び出されます。

しかし、sessionReachabilityDidChange の更新前にウォッチを発生させると、デリゲートは 1 回だけ呼び出され、到達不能状態を反映し、ウォッチ アプリの正しいアクティブ状態を反映するために再度呼び出すことができません。

プロジェクトのダウンロードはこちらhttps://dl.dropboxusercontent.com/u/2649851/WatchConnectivityTest.zip

編集:これはシミュレーターでは問題ではないようです。

4

0 に答える 0