@@ -51,106 +51,13 @@ function insertIOSImplCode(path){
5151 console . log ( rf ) ;
5252 } else {
5353 // console.log(searchDidlaunch[0]);
54- var oldValue = rf . match ( / \[ s e l f r e g i s t e r R e m o t e N o t i f i c a t i o n \] / )
54+ var oldValue = rf . match ( / G e T u i S d k r e g i s t e r R e m o t e N o t i f i c a t i o n / )
5555 if ( oldValue == null ) {
56- rf = rf . replace ( searchDidlaunch [ 0 ] , searchDidlaunch [ 0 ] + "\n \/\/ 接入个推\n\ [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self\]\ ;\n \/\/ APNs\n \[self registerRemoteNotification\]\;" ) ;
57- fs . writeFileSync ( path , rf , "utf-8" ) ;
56+ rf = rf . replace ( searchDidlaunch [ 0 ] , searchDidlaunch [ 0 ] + "\n \/\/ 接入个推\n \ [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:\[RCTGetuiModule sharedGetuiModule\] launchingOptions:launchOptions\]\ ;\n \/\/ APNs\n \[GeTuiSdk registerRemoteNotification: \(UNAuthorizationOptionSound \| UNAuthorizationOptionAlert \| UNAuthorizationOptionBadge\) \]\;" ) ;
57+ fs . writeFileSync ( path , rf , "utf-8" ) ;
5858 }
59-
60- }
61-
62- // 这里插入 registerRemoteNotification
63- var rf = fs . readFileSync ( path , "utf-8" ) ;
64- var search = rf . match ( / \n .* r e g i s t e r R e m o t e N o t i f i c a t i o n .* \n ? \{ \n / ) ;
65- if ( search == null ) {
66- console . log ( "没有匹配到 函数 registerRemoteNotification" ) ;
67- rf = rf . replace ( / \@ e n d / , "- (void)registerRemoteNotification {\n if \(\[\[UIDevice currentDevice\].systemVersion floatValue\] >= 10.0\) \{\n\#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 \/\/ Xcode 8编译会调用\nUNUserNotificationCenter \*center = \[UNUserNotificationCenter currentNotificationCenter\]\;\ncenter.delegate = self\;\[center requestAuthorizationWithOptions:\(UNAuthorizationOptionBadge \| UNAuthorizationOptionSound \| UNAuthorizationOptionAlert \| UNAuthorizationOptionCarPlay\) completionHandler:\^\(BOOL granted, NSError \*_Nullable error\) \{\nif \(!error\) \{\nNSLog\(\@\"request authorization succeeded!\"\)\;\n\}\n\}\]\;\n\[\[UIApplication sharedApplication\] registerForRemoteNotifications\]\;\n\#else \/\/ Xcode 7编译会调用\nUIUserNotificationType types = \(UIUserNotificationTypeAlert \| UIUserNotificationTypeSound \| UIUserNotificationTypeBadge\)\;\nUIUserNotificationSettings \*settings = \[UIUserNotificationSettings settingsForTypes:types categories:nil\]\;\n[[UIApplication sharedApplication] registerUserNotificationSettings:settings];\n[[UIApplication sharedApplication] registerForRemoteNotifications];\n\#endif\n} else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {\nUIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);\nUIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];\n[[UIApplication sharedApplication] registerUserNotificationSettings:settings];\n[[UIApplication sharedApplication] registerForRemoteNotifications];\n} else {\nUIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |\nUIRemoteNotificationTypeSound |\nUIRemoteNotificationTypeBadge);\n[[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];\n}\n}\n\@end" ) ;
68- // console.log(rf);
69- fs . writeFileSync ( path , rf , "utf-8" ) ;
7059 }
7160
72-
73- // 这个插入代码 didRegisterForRemoteNotificationsWithDeviceToken
74- var rf = fs . readFileSync ( path , "utf-8" ) ;
75- 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 [ ] * \{ / ) ;
76- var tokenMatchStr = "\n NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@\"<>\"]];\n token = [token stringByReplacingOccurrencesOfString:@\" \" withString:@\"\"];\n NSLog(\@\"\>\>\>[DeviceToken Success]:\%\@\", token);\n\/\/ [ GTSdk ]:向个推服务器注册deviceToken\n [GeTuiSdk registerDeviceTokenData:deviceToken];\n"
77- if ( search == null ) {
78- console . log ( "没有匹配到 函数 didRegisterForRemoteNotificationsWithDeviceToken" ) ;
79- rf = rf . replace ( / \@ e n d / , "/** 远程通知注册成功委托 */\n \- \(void\)application\:\(UIApplication \*\)application\ didRegisterForRemoteNotificationsWithDeviceToken\:\(NSData \*\)deviceToken \{" + tokenMatchStr + "\}\n\@end" ) ;
80- // console.log(rf);
81- fs . writeFileSync ( path , rf , "utf-8" ) ;
82- } else {
83- var oldValue = rf . match ( / \[ G e T u i S d k r e g i s t e r D e v i c e T o k e n D a t a : d e v i c e T o k e n / )
84- if ( oldValue == null ) {
85- rf = rf . replace ( search [ 0 ] , search [ 0 ] + tokenMatchStr ) ;
86- fs . writeFileSync ( path , rf , "utf-8" ) ;
87- }
88- }
89- //
90- // // 这里插入 didReceiveRemoteNotification
91- // var rf = fs.readFileSync(path,"utf-8");
92- // var search = rf.match(/\n.*didReceiveRemoteNotification\:\(NSDictionary \*\)userInfo[ ]*\{/);
93- // if (search == null) {
94- // console.log("没有匹配到 函数 didReceiveRemoteNotification");
95- // rf = rf.replace(/\@end/,"\- \(void\)application\:\(UIApplication \*\)application\ didReceiveRemoteNotification\:\(NSDictionary \*\)userInfo \{\n\[\[NSNotificationCenter\ defaultCenter\]\ postNotificationName\:kJPFDidReceiveRemoteNotification\ object\:userInfo\]\;\n\}\n\@end");
96- // // console.log(rf);
97- // fs.writeFileSync(path, rf, "utf-8");
98- // }
99- //
100- // 这里插入 didReceiveRemoteNotification fetchCompletionHandler
101- var rf = fs . readFileSync ( path , "utf-8" ) ;
102- var mathStr = "// [ GTSdk ]:将收到的APNs信息传给个推统计\n [GeTuiSdk handleRemoteNotification:userInfo];\n// 控制台打印接收APNs信息\nNSLog(@\">>>[Receive RemoteNotification]:%@\", userInfo);\n [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@\"type\":@\"apns\",@\"userInfo\":userInfo}];\n completionHandler(UIBackgroundFetchResultNewData);"
103- 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 \{ / ) ;
104- if ( search == null ) {
105- console . log ( "没有匹配到 函数 didReceiveRemoteNotification fetchCompletionHandler" ) ;
106- rf = rf . replace ( / \@ e n d / , "\- \(void\)application\:\(UIApplication \*\)application\ didReceiveRemoteNotification\:\(NSDictionary \*\)userInfo fetchCompletionHandler\:\(void\ \(\^\) \(UIBackgroundFetchResult\)\)completionHandler\ \{\n" + mathStr + "\n\}\n\@end" ) ;
107- // console.log(rf);
108- fs . writeFileSync ( path , rf , "utf-8" ) ;
109- }
110-
111- // 这里插入 willPresentNotification
112- var rf = fs . readFileSync ( path , "utf-8" ) ;
113- 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 / ) ;
114- if ( search == null ) {
115- console . log ( "没有匹配到 函数 willPresentNotification" ) ;
116- rf = rf . replace ( / \@ e n d / , "#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0\n\- \(void\)userNotificationCenter\:\(UNUserNotificationCenter\ \*\)center willPresentNotification\:\(UNNotification\ \*\)notification\ withCompletionHandler\:\(void\ \(\^\)\(UNNotificationPresentationOptions\)\)completionHandler\ \{\n [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@\"type\":@\"apns\",@\"userInfo\":notification.request.content.userInfo}]; completionHandler\(UNNotificationPresentationOptionAlert\)\;\n\}\n\@end" ) ;
117- // console.log(rf);
118- fs . writeFileSync ( path , rf , "utf-8" ) ;
119- }
120- //
121- // 这里插入 didReceiveNotificationResponse
122- var rf = fs . readFileSync ( path , "utf-8" ) ;
123- var search = rf . match ( / \n .* u s e r 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 / ) ;
124- if ( search == null ) {
125- console . log ( "没有匹配到 函数 didReceiveRemoteNotification" ) ;
126- rf = rf . replace ( / \@ e n d / , "\- \(void\)userNotificationCenter\:\(UNUserNotificationCenter\ \*\)center\ didReceiveNotificationResponse\:\(UNNotificationResponse\ \*\)response\ withCompletionHandler\:\(void\ \(\^\)\(\)\)completionHandler\ \{\n [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];\n [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_CLICK_NOTIFICATION object:response.notification.request.content.userInfo];\ncompletionHandler\(\)\;\n\}\n#endif\n@end" ) ;
127- // console.log(rf);
128- fs . writeFileSync ( path , rf , "utf-8" ) ;
129- }
130-
131- // 这里插入 SDK 注册 cid 成功回调
132- var rf = fs . readFileSync ( path , "utf-8" ) ;
133- var search = rf . match ( / \n .* G e T u i S d k D i d R e g i s t e r C l i e n t \: .* \{ \n / ) ;
134- var mathStr = "/** SDK成功注册 CID 回调 */\n-(void)GeTuiSdkDidRegisterClient:(NSString *)clientId{\n[[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_REGISTE_CLIENTID object:clientId];\n}\n"
135- if ( search == null ) {
136- console . log ( "没有匹配到 函数 GeTuiSdkDidRegisterClient" ) ;
137-
138- rf = rf . replace ( / \@ e n d / , mathStr + "\n@end" )
139- // console.log(rf);
140- fs . writeFileSync ( path , rf , "utf-8" ) ;
141- }
142-
143- // 这里插入 SDK收到透传消息回调
144- var rf = fs . readFileSync ( path , "utf-8" ) ;
145- var search = rf . match ( / \n .* a n d T a s k I d \: \( N S S t r i n g \* \) t a s k I d [ ] * a n d M s g I d \: .* \{ \n / ) ;
146- var mathStr = "/** SDK收到透传消息回调 */\n- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {\n// [ GTSdk ]:汇报个推自定义事件(反馈透传消息)\n[GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];\n\n// 数据转换\nNSString *payloadMsg = nil;\nif (payloadData) {\npayloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];\n}\n\n// 控制台打印日志\nNSString *msg = [NSString stringWithFormat:@\"taskId=%@,messageId:%@,payloadMsg:%@%@\", taskId, msgId, payloadMsg, offLine ? @\"<离线消息>\" : @\"\"];\nNSDictionary *userInfo = @{@\"taskId\":taskId,@\"msgId\":msgId,@\"payloadMsg\":payloadMsg,@\"offLine\":offLine?@\"YES\":@\"NO\"};\n[[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@\"type\":@\"payload\",@\"userInfo\":userInfo}];\nNSLog(@\">>[GTSdk ReceivePayload]:%@\", msg);\n}"
147- if ( search == null ) {
148- console . log ( "没有匹配到 函数 GeTuiSdkDidReceivePayloadData" ) ;
149-
150- rf = rf . replace ( / \@ e n d / , mathStr + "\n@end" )
151- // console.log(rf);
152- fs . writeFileSync ( path , rf , "utf-8" ) ;
153- }
15461}
15562
15663// 插入 Appdelegate.h 文件代码
@@ -168,8 +75,7 @@ function insertIOSHeaderCode(path) {
16875 if ( oldValue != null ) {
16976 return
17077 }
171- rf = rf . replace ( "\#import \<UIKit\/UIKit.h\>" , "\#import \<UIKit\/UIKit.h\>\n\#import \<RCTGetuiModule\/RCTGetuiModule.h\>\n\#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0\n\#import \<UserNotifications\/UserNotifications.h\>\n\#endif\n\#define kGtAppId \@\"" + appId + "\"\n\#define kGtAppKey \@\"" + appKey + "\"\n\#define kGtAppSecret \@\"" + appSecret + "\"\n" ) ;
172- rf = rf . replace ( "UIApplicationDelegate" , "UIApplicationDelegate,UNUserNotificationCenterDelegate,GeTuiSdkDelegate" ) ;
78+ rf = rf . replace ( "\#import \<UIKit\/UIKit.h\>" , "\#import \<UIKit\/UIKit.h\>\n\#if __has_include\(\<RCTGetuiModule\/RCTGetuiModule.h\>\)\n\#import \<RCTGetuiModule\/RCTGetuiModule.h\>\n\#elif __has_include\(\"RCTGetuiModule.h\"\)\n\#import \"RCTGetuiModule.h\"\n\#elif __has_include\(\<GtSdkRN\/RCTGetuiModule.h\>\)\n\#import \<GtSdkRN\/RCTGetuiModule.h\>\n\#endif\n#define kGtAppId \@\"" + appId + "\"\n\#define kGtAppKey \@\"" + appKey + "\"\n\#define kGtAppSecret \@\"" + appSecret + "\"\n" ) ;
17379 fs . writeFileSync ( path , rf , "utf-8" ) ;
17480}
17581
0 commit comments