答えて

1

あなたが置くことができます:あなたのIBAction内部

let center = UNUserNotificationCenter.current() 
    center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in 
     // Enable or disable features based on authorization. 
    } 
    UIApplication.shared.registerForRemoteNotifications() // you can also set here for local notification. 

UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) 
         completionHandler:^(BOOL granted, NSError * _Nullable error) { 
          // Enable or disable features based on authorization. 
         }]; 
[[UIApplication sharedApplication] registerForRemoteNotifications]; // you can also set here for local notification. 

スウィフト

のObjective-C。 Push notificationからCapabilities -

あなたはIBActionを持っているとPush Notificationtargetで活性化されていることを確認し、ファイル内のObjective-Cためスウィフトまたは#import <UserNotifications/UserNotifications.h>ためimport UserNotificationsを追加するも覚えておいてください。

0

のObjective-C:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
+0

'UIUserNotificationSettings'はiOSの10で廃止されますがUNNotificationSettings'代わりに'を使用しなければなりません。 https://developer.apple.com/documentation/uikit/uiusernotificationsettings – Mateusz

関連する問題