@@ -51,24 +51,13 @@ function insertJpushCode(path) {
5151 var rf = fs . readFileSync ( path , "utf-8" ) ;
5252 var searchDidlaunch = rf . match ( / \n .* d i d F i n i s h L a u n c h i n g W i t h O p t i o n s .* \n ? \{ / ) ;
5353 if ( searchDidlaunch == null ) {
54- console . log ( "没有匹配到 didFinishLaunchingWithOptions" ) ;
54+ console . log ( "没有匹配到 didFinishLaunchingWithOptions,将自动插入改方法 " ) ;
5555 console . log ( rf ) ;
5656 } else {
5757 // console.log(searchDidlaunch[0]);
5858 var oldValue = rf . match ( / \[ J P U S H S e r v i c e r e g i s t e r F o r R e m o t e N o t i f i c a t i o n T y p e s / )
5959 if ( oldValue == null ) {
60- rf = rf . replace ( searchDidlaunch [ 0 ] , searchDidlaunch [ 0 ] + "\n if \(\[\[UIDevice currentDevice\]\.systemVersion floatValue\] >= 10.0\) \{\n \#ifdef NSFoundationVersionNumber_iOS_9_x_Max\n JPUSHRegisterEntity \* entity \= \[\[JPUSHRegisterEntity alloc\] init\]\;\n entity\.types \= UNAuthorizationOptionAlert\|UNAuthorizationOptionBadge\|UNAuthorizationOptionSound\;\n \[JPUSHService registerForRemoteNotificationConfig\:entity delegate\:self\]\;\n \n\#endif\n\} else if \(\[\[UIDevice currentDevice\]\.systemVersion floatValue\] \>\= 8\.0\) \{\n\
61- \[JPUSHService registerForRemoteNotificationTypes\:\(UIUserNotificationTypeBadge \|\n\
62- UIUserNotificationTypeSound \|\n\
63- UIUserNotificationTypeAlert\)\n\
64- categories\:nil\]\;\n\
65- \} else \{\n\
66- \[JPUSHService registerForRemoteNotificationTypes\:\(UIRemoteNotificationTypeBadge \|\n\
67- UIRemoteNotificationTypeSound \|\n\
68- UIRemoteNotificationTypeAlert)\n\
69- categories\:nil\]\;\n\
70- }\n\
71- \n\
60+ rf = rf . replace ( searchDidlaunch [ 0 ] , searchDidlaunch [ 0 ] + "\nJPUSHRegisterEntity \* entity \= \[\[JPUSHRegisterEntity alloc\] init\]\;\n entity\.types \= UNAuthorizationOptionAlert\|UNAuthorizationOptionBadge\|UNAuthorizationOptionSound\;\n \[JPUSHService registerForRemoteNotificationConfig\:entity delegate\:self\]\;\n\
7261 \[JPUSHService setupWithOption\:launchOptions appKey\:\@\"" + appKey + "\"\n\
7362 channel\:nil apsForProduction\:nil\]\;" ) ;
7463 fs . writeFileSync ( path , rf , "utf-8" ) ;
@@ -82,7 +71,7 @@ function insertJpushCode(path) {
8271 var search = rf . match ( / \n .* d i d R e g i s t e r F o r R e m o t e N o t i f i c a t i o n s W i t h D e v i c e T o k e n \: \( N S D a t a \* \) d e v i c e T o k e n [ ] * \{ / ) ;
8372
8473 if ( search == null ) {
85- console . log ( "没有匹配到 函数 didRegisterForRemoteNotificationsWithDeviceToken" ) ;
74+ console . log ( "没有匹配到 函数 didRegisterForRemoteNotificationsWithDeviceToken,将自动插入改方法 " ) ;
8675 rf = rf . replace ( / \@ e n d / , "\- \(void\)application\:\(UIApplication \*\)application\ didRegisterForRemoteNotificationsWithDeviceToken\:\(NSData \*\)deviceToken \{\n\[JPUSHService registerDeviceToken:deviceToken\]\;\n\}\n\@end" ) ;
8776 // console.log(rf);
8877 fs . writeFileSync ( path , rf , "utf-8" ) ;
@@ -102,7 +91,7 @@ function insertJpushCode(path) {
10291 var rf = fs . readFileSync ( path , "utf-8" ) ;
10392 var search = rf . match ( / \n .* d i d R e c e i v e R e m o t e N o t i f i c a t i o n \: \( N S D i c t i o n a r y \* \) u s e r I n f o [ ] * \{ / ) ;
10493 if ( search == null ) {
105- console . log ( "没有匹配到 函数 didReceiveRemoteNotification" ) ;
94+ console . log ( "没有匹配到 函数 didReceiveRemoteNotification,将自动插入改方法 " ) ;
10695 rf = rf . replace ( / \@ e n d / , "\- \(void\)application\:\(UIApplication \*\)application\ didReceiveRemoteNotification\:\(NSDictionary \*\)userInfo \{\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:userInfo\]\;\n\}\n\@end" ) ;
10796 // console.log(rf);
10897 fs . writeFileSync ( path , rf , "utf-8" ) ;
@@ -112,7 +101,7 @@ function insertJpushCode(path) {
112101 var rf = fs . readFileSync ( path , "utf-8" ) ;
113102 var search = rf . match ( / \n .* d i d R e c e i v e R e m o t e N o t i f i c a t i o n \: [ ] * \( N S D i c t i o n a r y \* \) [ ] * u s e r I n f o [ ] * f e t c h C o m p l e t i o n H a n d l e r \: \( v o i d [ ] * \( \^ \) [ ] * \( U I B a c k g r o u n d F e t c h R e s u l t \) \) c o m p l e t i o n H a n d l e r \{ / ) ;
114103 if ( search == null ) {
115- console . log ( "没有匹配到 函数 didReceiveRemoteNotification fetchCompletionHandler" ) ;
104+ console . log ( "没有匹配到 函数 didReceiveRemoteNotification fetchCompletionHandler,将自动插入改方法 " ) ;
116105 rf = rf . replace ( / \@ e n d / , "\- \(void\)application\:\(UIApplication \*\)application\ didReceiveRemoteNotification\:\(NSDictionary \*\)userInfo fetchCompletionHandler\:\(void\ \(\^\) \(UIBackgroundFetchResult\)\)completionHandler\ \{\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:userInfo\]\;\n\}\n\@end" ) ;
117106 // console.log(rf);
118107 fs . writeFileSync ( path , rf , "utf-8" ) ;
@@ -122,21 +111,28 @@ function insertJpushCode(path) {
122111 var rf = fs . readFileSync ( path , "utf-8" ) ;
123112 var search = rf . match ( / \n .* w i l l P r e s e n t N o t i f i c a t i o n \: \( U N N o t i f i c a t i o n \* \) n o t i f i c a t i o n [ ] * w i t h C o m p l e t i o n H a n d l e r \: .* \{ \n / ) ;
124113 if ( search == null ) {
125- console . log ( "没有匹配到 函数 willPresentNotification" ) ;
126- rf = rf . replace ( / \@ e n d / , "\- \(void\)jpushNotificationCenter\:\(UNUserNotificationCenter\ \*\)center willPresentNotification\:\(UNNotification\ \*\)notification\ withCompletionHandler\:\(void\ \(\^\)\(NSInteger\)\)completionHandler\ \{\n NSDictionary\ \* userInfo\ \=\ notification\.request\.content\.userInfo\;\n if\(\[notification\.request\.trigger\ isKindOfClass\:\[UNPushNotificationTrigger\ class\]\]\)\ \{\n \[JPUSHService\ handleRemoteNotification\:userInfo\]\;\n \[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:userInfo\]\;\n \ \ \ \}\n completionHandler\(UNNotificationPresentationOptionAlert\)\;\n\}\n\@end" ) ;
127- // console.log(rf);
114+ console . log ( "没有匹配到 函数 willPresentNotification,将自动插入改方法" ) ;
115+ rf = rf . replace ( / \@ e n d / , "\- \(void\)jpushNotificationCenter\:\(UNUserNotificationCenter\ \*\)center willPresentNotification\:\(UNNotification\ \*\)notification\ withCompletionHandler\:\(void\ \(\^\)\(NSInteger\)\)completionHandler\ \{\n NSDictionary\ \* userInfo\ \=\ notification\.request\.content\.userInfo\;\n \[JPUSHService\ handleRemoteNotification\:userInfo\]\;\n \[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:userInfo\]\;\n \ \ \ \n completionHandler\(UNNotificationPresentationOptionAlert\)\;\n\}\n\@end" ) ;
128116 fs . writeFileSync ( path , rf , "utf-8" ) ;
129117 }
130118
131119 // 这里插入 didReceiveNotificationResponse
132120 var rf = fs . readFileSync ( path , "utf-8" ) ;
133121 var search = rf . match ( / \n .* j p u s h N o t i f i c a t i o n C e n t e r \: \( U N U s e r N o t i f i c a t i o n C e n t e r \* \) c e n t e r [ ] * d i d R e c e i v e N o t i f i c a t i o n R e s p o n s e \: \( U N N o t i f i c a t i o n R e s p o n s e \ \* \) r e s p o n s e .* \{ \n / ) ;
134122 if ( search == null ) {
135- console . log ( "没有匹配到 函数 didReceiveRemoteNotification" ) ;
136- rf = rf . replace ( / \@ e n d / , "\- \(void\)jpushNotificationCenter\:\(UNUserNotificationCenter\ \*\)center\ didReceiveNotificationResponse\:\(UNNotificationResponse\ \*\)response\ withCompletionHandler\:\(void\ \(\^\)\(\)\)completionHandler\ \{\nNSDictionary\ \*\ userInfo\ \=\ response\.notification\.request\.content\.userInfo\;\nif\(\[response\.notification\.request\.trigger\ isKindOfClass\:\[UNPushNotificationTrigger\ class\]\]\)\ \{\ n\[JPUSHService\ handleRemoteNotification\:userInfo\]\;\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFOpenNotification\ object:userInfo\]\;\n\} \ncompletionHandler\(\)\;\n\}\n\@end" ) ;
123+ console . log ( "没有匹配到 函数 didReceiveRemoteNotification,将自动插入改方法 " ) ;
124+ rf = rf . replace ( / \@ e n d / , "\- \(void\)jpushNotificationCenter\:\(UNUserNotificationCenter\ \*\)center\ didReceiveNotificationResponse\:\(UNNotificationResponse\ \*\)response\ withCompletionHandler\:\(void\ \(\^\)\(\)\)completionHandler\ \{\nNSDictionary\ \*\ userInfo\ \=\ response\.notification\.request\.content\.userInfo\;\n\[JPUSHService\ handleRemoteNotification\:userInfo\]\;\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFOpenNotification\ object:userInfo\]\;\n\ncompletionHandler\(\)\;\n\}\n\@end" ) ;
137125 // console.log(rf);
138126 fs . writeFileSync ( path , rf , "utf-8" ) ;
139127 }
128+
129+ var rf = fs . readFileSync ( path , "utf-8" ) ;
130+ var search = rf . match ( / \n .* d i d R e c e i v e L o c a l N o t i f i c a t i o n \: \( U I L o c a l N o t i f i c a t i o n \* \) n o t i f i c a t i o n [ ] * \{ / ) ;
131+ if ( search == null ) {
132+ console . log ( "没有匹配到 函数 didReceiveLocalNotification,将自动插入改方法" ) ;
133+ rf = rf . replace ( / \@ e n d / , "\- \(void\)application\:\(UIApplication \*\)application\ didReceiveLocalNotification\:\(UILocalNotification \*\)notification \{\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:notification.userInfo\]\;\n\}\n\@end" ) ;
134+ fs . writeFileSync ( path , rf , "utf-8" ) ;
135+ }
140136}
141137
142138
0 commit comments