0

因此,我通过了 userInfo NSDictionary:

    [[WKExtension sharedExtension] scheduleBackgroundRefreshWithPreferredDate:[NSDate dateWithTimeIntervalSinceNow:10] 
        userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"timer", @"reason", nil]
        scheduledCompletion:^(NSError * _Nullable error) { ... }



但是,当接收到任务时,task.userInfo 为 nil:

- (void)handleBackgroundTasks:(NSSet<WKRefreshBackgroundTask *> *)backgroundTasks {
    for (WKRefreshBackgroundTask * task in backgroundTasks) {
            WKApplicationRefreshBackgroundTask *backgroundTask = (WKApplicationRefreshBackgroundTask*)task;

            if (task.userInfo) {
                NSDictionary *userInfo = (NSDictionary *)task.userInfo;
                NSString *reason = [userInfo objectForKey:@"reason"];
                NSLog(@"reason: %@", reason);
            } else {
                NSLog(@"no userInfo %@", task.debugDescription);
            }


我在这里想念什么?

谢谢,皮特

4

0 回答 0