WKApplicationRefreshBackgroundTask is missing userInfo passed via scheduleBackgroundRefreshWithPreferredDate

98 Views Asked by At

I'm pass the userInfo NSDictionary thusly:

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



But, when the task is received in, task.userInfo is 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);
            }


What am I missing here?

Thx, Pete

0

There are 0 best solutions below