0

我有一个允许设备运行更新的代码。当 ipad 没有在 iOS11 下获取信息的引导访问时,它可以完美运行(并且它在 iOS10 和引导访问下工作):

- (void)viewDidLoad
{
...
      UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
        content.title = [NSString localizedUserNotificationStringForKey:@"Update!" arguments:nil];
        content.body = [NSString localizedUserNotificationStringForKey:@"Update!"
                                                             arguments:nil];

        // Configure the trigger for a 7am update.
        NSDateComponents* date = [[NSDateComponents alloc] init];
        date.hour = 18;
        date.minute = 31;
        UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger
                                                  triggerWithDateMatchingComponents:date repeats:NO];

        // Create the request object.
        UNNotificationRequest* request = [UNNotificationRequest
                                          requestWithIdentifier:@"update" content:content trigger:trigger];

        UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
            if (error != nil) {
                NSLog(@"%@", error.localizedDescription);
            }
        }];
    }

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center
           willPresentNotification:(UNNotification *)notification
             withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
        // Update the app interface directly.
        NSLog(@"");
        // Play a sound.
        completionHandler(UNNotificationPresentationOptionSound);
    }

我发现了Ticket,但没有详尽的解释来完成它:

iOS11下是否可以启动引导访问通知?

提前致谢。

4

1 回答 1

1

看来这只不过是 iOS 11.2.5 beta 4 中修复的一个 iOS 错误。请在此处查看我自己的问题以获取更多信息。

如果您可以等到 iOS 11.2.5 发布(希望根据 Apple很快发布),问题应该会自行解决。否则,您将需要研究诸如套接字系统之类的东西。

于 2018-01-15T23:53:36.280 回答