我有一个允许设备运行更新的代码。当 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下是否可以启动引导访问通知?
提前致谢。