@@ -67,23 +67,6 @@ - (void)getSubscriptions: (CDVInvokedUrlCommand *)command
6767
6868- (void )subscribe : (CDVInvokedUrlCommand *)command
6969{
70- // Not sure if this is necessary
71- if ([[UIApplication sharedApplication ] respondsToSelector: @selector (registerUserNotificationSettings: )]) {
72- UIUserNotificationSettings *settings =
73- [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert |
74- UIUserNotificationTypeBadge |
75- UIUserNotificationTypeSound
76- categories: nil ];
77- [[UIApplication sharedApplication ] registerUserNotificationSettings: settings];
78- [[UIApplication sharedApplication ] registerForRemoteNotifications ];
79- }
80- else {
81- [[UIApplication sharedApplication ] registerForRemoteNotificationTypes:
82- UIRemoteNotificationTypeBadge |
83- UIRemoteNotificationTypeAlert |
84- UIRemoteNotificationTypeSound];
85- }
86-
8770 CDVPluginResult* pluginResult = nil ;
8871 PFInstallation *currentInstallation = [PFInstallation currentInstallation ];
8972 NSString *channel = [command.arguments objectAtIndex: 0 ];
@@ -123,10 +106,28 @@ - (void)registerForPN {
123106
124107 if (!self.hasRegistered ){
125108 NSLog (@" ParsePushPlugin is registering your device for PN" );
126- UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
127- UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: userNotificationTypes categories: nil ];
128- [application registerUserNotificationSettings: settings];
129- [application registerForRemoteNotifications ];
109+
110+ if (IsAtLeastiOSVersion (@" 10.0" )) {
111+
112+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
113+ center.delegate = self;
114+
115+ [center requestAuthorizationWithOptions: (UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge ) completionHandler: ^(BOOL granted, NSError * _Nullable error){
116+ if ( !error ){
117+ [application registerForRemoteNotifications ];
118+ }
119+ }];
120+
121+ }
122+ else if (IsAtLeastiOSVersion (@" 8.0" )) {
123+
124+ if ([application respondsToSelector: @selector (registerUserNotificationSettings: )]) {
125+ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories: nil ];
126+ [application registerUserNotificationSettings: settings];
127+ [application registerForRemoteNotifications ];
128+ }
129+
130+ }
130131
131132 self.hasRegistered = true ;
132133 }
@@ -185,4 +186,13 @@ + (void)saveDeviceTokenToInstallation: (NSData*)deviceToken
185186 [currentInstallation saveInBackground ];
186187}
187188
189+ -(void )userNotificationCenter : (UNUserNotificationCenter *)center willPresentNotification : (UNNotification *)notification withCompletionHandler : (void (^)(UNNotificationPresentationOptions ))completionHandler {
190+ NSLog (@" User info %@ " , notification.request .content .userInfo );
191+ completionHandler (UNNotificationPresentationOptionAlert );
192+ }
193+
194+ -(void )userNotificationCenter : (UNUserNotificationCenter *)center didReceiveNotificationResponse : (UNNotificationResponse *)response withCompletionHandler : (void (^)())completionHandler {
195+ NSLog (@" User info %@ " , response.notification .request .content .userInfo );
196+ }
197+
188198@end
0 commit comments