cordova-plugin-appice 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
-
2
- #import "AppDelegate.h"
3
-
4
- @interface AppDelegate (AppICEPlugin)
5
-
6
- +(id) delegate;
7
-
8
- @end
1
+
2
+ #import "AppDelegate.h"
3
+
4
+ @interface AppDelegate (AppICEPlugin)
5
+
6
+ +(id) delegate;
7
+
8
+ @end
@@ -1,259 +1,259 @@
1
-
2
- #import "AppDelegate+AppICEPlugin.h"
3
- #import "AppICEPlugin.h"
4
- #import <objc/runtime.h>
5
- #import "appICE.h"
6
-
7
-
8
-
9
-
10
-
11
- #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
12
- @import UserNotifications;
13
- #endif
14
-
15
- #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
16
- @interface AppDelegate () <UNUserNotificationCenterDelegate>
17
- @end
18
- #endif
19
-
20
- #define kApplicationInBackgroundKey @"applicationInBackground"
21
- #define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
22
-
23
- @implementation AppDelegate (AppICEPlugin)
24
-
25
- static id appdelegate;
26
- typedef void (*OriginalImpType)(id self, SEL selector);
27
- static OriginalImpType originalImp;
28
- + (void)load {
29
- /*
30
- //for did finish launch method
31
- Method originalDidFinishLaunchingWithOptions = class_getInstanceMethod(self, @selector(application:didFinishLaunchingWithOptions:));
32
-
33
- Method swizzledDidFinishLaunchingWithOptions = class_getInstanceMethod(self, @selector(application:swizzledDidFinishLaunchingWithOptions:));
34
- method_exchangeImplementations(originalDidFinishLaunchingWithOptions, swizzledDidFinishLaunchingWithOptions);
35
-
36
-
37
-
38
- //for Notification received
39
- Method originalDidReceiveRemoteNotification = class_getInstanceMethod(self, @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:));
40
- Method swizzleDidReceiveRemoteNotification = class_getInstanceMethod(self, @selector(application:swizzleddidReceiveRemoteNotification:fetchCompletionHandler:));
41
- method_exchangeImplementations(originalDidReceiveRemoteNotification, swizzleDidReceiveRemoteNotification);
42
-
43
-
44
-
45
-
46
- //for remote notfication failed
47
- Method originaldidFailToRegisterForRemoteNotificationsWithError = class_getInstanceMethod(self, @selector(application:didFailToRegisterForRemoteNotificationsWithError:));
48
- Method swizzleddidFailToRegisterForRemoteNotificationsWithError = class_getInstanceMethod(self, @selector(application:swizzleddidFailToRegisterForRemoteNotificationsWithError:));
49
- method_exchangeImplementations(originaldidFailToRegisterForRemoteNotificationsWithError, swizzleddidFailToRegisterForRemoteNotificationsWithError);
50
- NSLog(@"Appice+delegate loaded"); */
51
-
52
- //for device token register
53
- Method originaldidRegisterForRemoteNotificationsWithDeviceToken = class_getInstanceMethod(self, @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:));
54
- Method swizzleddidRegisterForRemoteNotificationsWithDeviceToken = class_getInstanceMethod(self, @selector(application:swizzleddidRegisterForRemoteNotificationsWithDeviceToken:));
55
- method_exchangeImplementations(originaldidRegisterForRemoteNotificationsWithDeviceToken, swizzleddidRegisterForRemoteNotificationsWithDeviceToken);
56
- }
57
-
58
- +(id) delegate{
59
- return appdelegate;
60
- }
61
-
62
- - (id)init
63
- {
64
- self = [super init];
65
-
66
- appdelegate = self;
67
-
68
- NSLog(@"Appice+delegate init");
69
-
70
- return self;
71
- }
72
-
73
- - (void)setApplicationInBackground:(NSNumber *)applicationInBackground {
74
- objc_setAssociatedObject(self, kApplicationInBackgroundKey, applicationInBackground, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
75
- }
76
-
77
- - (NSNumber *)applicationInBackground {
78
- return objc_getAssociatedObject(self, kApplicationInBackgroundKey);
79
- }
80
- -(void)application:(UIApplication *)application swizzleddidReceiveRemoteNotification:(NSDictionary *)userInfo
81
- fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
82
- @try {
83
- BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
84
- if(appIceServer)
85
- {
86
- [[AppICEPlugin appice] onHandleRemoteUNotification:userInfo];
87
- completionHandler(UIBackgroundFetchResultNewData);
88
- }
89
- else
90
- {
91
- [self application:application swizzleddidReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
92
- }
93
- }
94
- @catch (NSException *exception) {
95
- NSLog(@"exception from did receive notfication cordova = %@",exception.reason);
96
- } @finally {
97
-
98
- }
99
- }
100
-
101
- - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
102
- [self application:application swizzledDidFinishLaunchingWithOptions:launchOptions];
103
-
104
- [self registerForRemoteNotification];
105
-
106
- self.applicationInBackground = @(YES);
107
-
108
- return YES;
109
- }
110
-
111
- - (void)registerForRemoteNotification {
112
- if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) {
113
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
114
- center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
115
- if( !error ){
116
- dispatch_async(dispatch_get_main_queue(), ^{
117
- [[UIApplication sharedApplication] registerForRemoteNotifications];
118
- });
119
- }
120
- }];
121
- }
122
- else {
123
- [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
124
- [[UIApplication sharedApplication] registerForRemoteNotifications];
125
- }
126
- }
127
-
128
- #pragma mark - Register Remote Notification
129
-
130
- - (void)application:(UIApplication*)application swizzleddidRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
131
- @try {
132
- [[AppICEPlugin appice] handleToken:deviceToken];
133
- } @catch(NSException *e){}
134
- }
135
-
136
- - (void)application:(UIApplication*)application swizzleddidFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
137
- @try {
138
- [[AppICEPlugin appice] handleTokenError:error];
139
- } @catch (NSException *exception) {
140
- }
141
- }
142
- // - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
143
- // {
144
- // [[AppICEPlugin appice] handleToken:deviceToken];
145
- // }
146
- #pragma mark - Handle Notification info
147
-
148
- - (void) application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification {
149
-
150
- @try {
151
- [[AppICEPlugin appice] onHandleLocalNotification:notification];
152
- } @catch (NSException *exception) {
153
- }
154
- }
155
-
156
- /*- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
157
- @try {
158
- [[AppICEPlugin appice] onHandleRemoteUNotification:userInfo];
159
- } @catch (NSException *exception) {
160
- }
161
- }*/
162
-
163
-
164
- #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
165
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
166
- willPresentNotification:(UNNotification *)notification
167
- withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
168
- @try {
169
- [[AppICEPlugin appice] onHandleRemoteUNotification:notification.request.content.userInfo];
170
-
171
- completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
172
- } @catch (NSException *exception) {
173
-
174
- } @finally {
175
-
176
- }
177
- }
178
-
179
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{
180
-
181
- @try {
182
- NSDictionary *userInfo = response.notification.request.content.userInfo;
183
-
184
- [[AppICEPlugin appice] onHandleNotificationUResponse:userInfo];
185
-
186
- completionHandler();
187
- } @catch (NSException *exception) {
188
-
189
- } @finally {
190
-
191
- }
192
- }
193
- #endif
194
-
195
- #pragma mark - Handle Notification Action
196
-
197
- - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler {
198
-
199
- @try {
200
- [[AppICEPlugin appice] onHandleActionForIdentifier:identifier];
201
-
202
- if (completionHandler) {
203
- completionHandler();
204
- }
205
- } @catch (NSException *exception) {
206
-
207
- } @finally {
208
-
209
- }
210
- }
211
-
212
- - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
213
- {
214
- @try {
215
- [[AppICEPlugin appice] onHandleActionForIdentifier:identifier];
216
-
217
- if (completionHandler) {
218
- completionHandler();
219
- }
220
- } @catch (NSException *exception) {
221
-
222
- } @finally {
223
-
224
- }
225
- }
226
-
227
- #pragma mark - OpenURL Functions
228
-
229
- - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
230
- @try {
231
- if (!url) {
232
- return NO;
233
- }
234
- [[AppICEPlugin appice] onHandleOpenURLNotification:url];
235
- } @catch (NSException *exception) {
236
- }
237
- return YES;
238
- }
239
-
240
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
241
- @try {
242
- if (!url) {
243
- return NO;
244
- }
245
- [[AppICEPlugin appice] onHandleOpenURLNotification:url];
246
-
247
- } @catch (NSException *exception) {
248
- }
249
- return YES;
250
- }
251
-
252
- - (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion {
253
- @try {
254
- [[AppICEPlugin appice] onHandleOpenURLNotification:url];
255
- } @catch (NSException *exception) {
256
- }
257
- }
258
-
259
- @end
1
+
2
+ #import "AppDelegate+AppICEPlugin.h"
3
+ #import "AppICEPlugin.h"
4
+ #import <objc/runtime.h>
5
+ #import "appICE.h"
6
+
7
+
8
+
9
+
10
+
11
+ #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
12
+ @import UserNotifications;
13
+ #endif
14
+
15
+ #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
16
+ @interface AppDelegate () <UNUserNotificationCenterDelegate>
17
+ @end
18
+ #endif
19
+
20
+ #define kApplicationInBackgroundKey @"applicationInBackground"
21
+ #define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
22
+
23
+ @implementation AppDelegate (AppICEPlugin)
24
+
25
+ static id appdelegate;
26
+ typedef void (*OriginalImpType)(id self, SEL selector);
27
+ static OriginalImpType originalImp;
28
+ + (void)load {
29
+ /*
30
+ //for did finish launch method
31
+ Method originalDidFinishLaunchingWithOptions = class_getInstanceMethod(self, @selector(application:didFinishLaunchingWithOptions:));
32
+
33
+ Method swizzledDidFinishLaunchingWithOptions = class_getInstanceMethod(self, @selector(application:swizzledDidFinishLaunchingWithOptions:));
34
+ method_exchangeImplementations(originalDidFinishLaunchingWithOptions, swizzledDidFinishLaunchingWithOptions);
35
+
36
+
37
+
38
+ //for Notification received
39
+ Method originalDidReceiveRemoteNotification = class_getInstanceMethod(self, @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:));
40
+ Method swizzleDidReceiveRemoteNotification = class_getInstanceMethod(self, @selector(application:swizzleddidReceiveRemoteNotification:fetchCompletionHandler:));
41
+ method_exchangeImplementations(originalDidReceiveRemoteNotification, swizzleDidReceiveRemoteNotification);
42
+
43
+
44
+
45
+
46
+ //for remote notfication failed
47
+ Method originaldidFailToRegisterForRemoteNotificationsWithError = class_getInstanceMethod(self, @selector(application:didFailToRegisterForRemoteNotificationsWithError:));
48
+ Method swizzleddidFailToRegisterForRemoteNotificationsWithError = class_getInstanceMethod(self, @selector(application:swizzleddidFailToRegisterForRemoteNotificationsWithError:));
49
+ method_exchangeImplementations(originaldidFailToRegisterForRemoteNotificationsWithError, swizzleddidFailToRegisterForRemoteNotificationsWithError);
50
+ NSLog(@"Appice+delegate loaded"); */
51
+
52
+ //for device token register
53
+ Method originaldidRegisterForRemoteNotificationsWithDeviceToken = class_getInstanceMethod(self, @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:));
54
+ Method swizzleddidRegisterForRemoteNotificationsWithDeviceToken = class_getInstanceMethod(self, @selector(application:swizzleddidRegisterForRemoteNotificationsWithDeviceToken:));
55
+ method_exchangeImplementations(originaldidRegisterForRemoteNotificationsWithDeviceToken, swizzleddidRegisterForRemoteNotificationsWithDeviceToken);
56
+ }
57
+
58
+ +(id) delegate{
59
+ return appdelegate;
60
+ }
61
+
62
+ - (id)init
63
+ {
64
+ self = [super init];
65
+
66
+ appdelegate = self;
67
+
68
+ NSLog(@"Appice+delegate init");
69
+
70
+ return self;
71
+ }
72
+
73
+ - (void)setApplicationInBackground:(NSNumber *)applicationInBackground {
74
+ objc_setAssociatedObject(self, kApplicationInBackgroundKey, applicationInBackground, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
75
+ }
76
+
77
+ - (NSNumber *)applicationInBackground {
78
+ return objc_getAssociatedObject(self, kApplicationInBackgroundKey);
79
+ }
80
+ -(void)application:(UIApplication *)application swizzleddidReceiveRemoteNotification:(NSDictionary *)userInfo
81
+ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
82
+ @try {
83
+ BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
84
+ if(appIceServer)
85
+ {
86
+ [[AppICEPlugin appice] onHandleRemoteUNotification:userInfo];
87
+ completionHandler(UIBackgroundFetchResultNewData);
88
+ }
89
+ else
90
+ {
91
+ [self application:application swizzleddidReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
92
+ }
93
+ }
94
+ @catch (NSException *exception) {
95
+ NSLog(@"exception from did receive notfication cordova = %@",exception.reason);
96
+ } @finally {
97
+
98
+ }
99
+ }
100
+
101
+ - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
102
+ [self application:application swizzledDidFinishLaunchingWithOptions:launchOptions];
103
+
104
+ [self registerForRemoteNotification];
105
+
106
+ self.applicationInBackground = @(YES);
107
+
108
+ return YES;
109
+ }
110
+
111
+ - (void)registerForRemoteNotification {
112
+ if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) {
113
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
114
+ center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
115
+ if( !error ){
116
+ dispatch_async(dispatch_get_main_queue(), ^{
117
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
118
+ });
119
+ }
120
+ }];
121
+ }
122
+ else {
123
+ [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
124
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
125
+ }
126
+ }
127
+
128
+ #pragma mark - Register Remote Notification
129
+
130
+ - (void)application:(UIApplication*)application swizzleddidRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
131
+ @try {
132
+ [[AppICEPlugin appice] handleToken:deviceToken];
133
+ } @catch(NSException *e){}
134
+ }
135
+
136
+ - (void)application:(UIApplication*)application swizzleddidFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
137
+ @try {
138
+ [[AppICEPlugin appice] handleTokenError:error];
139
+ } @catch (NSException *exception) {
140
+ }
141
+ }
142
+ // - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
143
+ // {
144
+ // [[AppICEPlugin appice] handleToken:deviceToken];
145
+ // }
146
+ #pragma mark - Handle Notification info
147
+
148
+ - (void) application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification {
149
+
150
+ @try {
151
+ [[AppICEPlugin appice] onHandleLocalNotification:notification];
152
+ } @catch (NSException *exception) {
153
+ }
154
+ }
155
+
156
+ /*- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
157
+ @try {
158
+ [[AppICEPlugin appice] onHandleRemoteUNotification:userInfo];
159
+ } @catch (NSException *exception) {
160
+ }
161
+ }*/
162
+
163
+
164
+ #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
165
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
166
+ willPresentNotification:(UNNotification *)notification
167
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
168
+ @try {
169
+ [[AppICEPlugin appice] onHandleRemoteUNotification:notification.request.content.userInfo];
170
+
171
+ completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
172
+ } @catch (NSException *exception) {
173
+
174
+ } @finally {
175
+
176
+ }
177
+ }
178
+
179
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{
180
+
181
+ @try {
182
+ NSDictionary *userInfo = response.notification.request.content.userInfo;
183
+
184
+ [[AppICEPlugin appice] onHandleNotificationUResponse:userInfo];
185
+
186
+ completionHandler();
187
+ } @catch (NSException *exception) {
188
+
189
+ } @finally {
190
+
191
+ }
192
+ }
193
+ #endif
194
+
195
+ #pragma mark - Handle Notification Action
196
+
197
+ - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler {
198
+
199
+ @try {
200
+ [[AppICEPlugin appice] onHandleActionForIdentifier:identifier];
201
+
202
+ if (completionHandler) {
203
+ completionHandler();
204
+ }
205
+ } @catch (NSException *exception) {
206
+
207
+ } @finally {
208
+
209
+ }
210
+ }
211
+
212
+ - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
213
+ {
214
+ @try {
215
+ [[AppICEPlugin appice] onHandleActionForIdentifier:identifier];
216
+
217
+ if (completionHandler) {
218
+ completionHandler();
219
+ }
220
+ } @catch (NSException *exception) {
221
+
222
+ } @finally {
223
+
224
+ }
225
+ }
226
+
227
+ #pragma mark - OpenURL Functions
228
+
229
+ - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
230
+ @try {
231
+ if (!url) {
232
+ return NO;
233
+ }
234
+ [[AppICEPlugin appice] onHandleOpenURLNotification:url];
235
+ } @catch (NSException *exception) {
236
+ }
237
+ return YES;
238
+ }
239
+
240
+ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
241
+ @try {
242
+ if (!url) {
243
+ return NO;
244
+ }
245
+ [[AppICEPlugin appice] onHandleOpenURLNotification:url];
246
+
247
+ } @catch (NSException *exception) {
248
+ }
249
+ return YES;
250
+ }
251
+
252
+ - (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion {
253
+ @try {
254
+ [[AppICEPlugin appice] onHandleOpenURLNotification:url];
255
+ } @catch (NSException *exception) {
256
+ }
257
+ }
258
+
259
+ @end