UserNotification
を発射することができません(iOSの10)
表示されていません。UserNotificationは
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions options = (UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound);
center.delegate = self;
[center requestAuthorizationWithOptions: options
completionHandler: ^(BOOL granted, NSError * _Nullable error) {
if (granted) {
NSLog(@"Granted notifications!");
}
}];
//
これは動作しますが、私はログを参照してください。
はその後、私が持っている:
-(void)application: (UIApplication *)application performFetchWithCompletionHandler: (void (^)(UIBackgroundFetchResult))completionHandler {
//
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = NSLocalizedString(@"Updates are available", nil);
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval: 1
repeats: NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier: @"IDLocalNotification"
content: content
trigger: trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest: request withCompletionHandler: ^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Notification was requested!");
}
}];
繰り返しますが、これは動作しますが、私はログを参照してください。
しかし、私の画面には通知が表示されません(トリガーの遅延はわずか1秒ですが、大きな値も試しました)。
また、willPresentNotification
代理人メソッドには到達しません。
私には何が欠けていますか?
アプリがフォアグラウンドになっている場合は、アプリを起動したときにあなた自身の通知が表示されません。 – Larme