@@ -67,23 +67,6 @@ - (void)getSubscriptions: (CDVInvokedUrlCommand *)command
67
67
68
68
- (void )subscribe : (CDVInvokedUrlCommand *)command
69
69
{
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
-
87
70
CDVPluginResult* pluginResult = nil ;
88
71
PFInstallation *currentInstallation = [PFInstallation currentInstallation ];
89
72
NSString *channel = [command.arguments objectAtIndex: 0 ];
@@ -123,10 +106,28 @@ - (void)registerForPN {
123
106
124
107
if (!self.hasRegistered ){
125
108
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
+ }
130
131
131
132
self.hasRegistered = true ;
132
133
}
@@ -185,4 +186,13 @@ + (void)saveDeviceTokenToInstallation: (NSData*)deviceToken
185
186
[currentInstallation saveInBackground ];
186
187
}
187
188
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
+
188
198
@end
0 commit comments