提交 ec32b09b authored 作者: 史晓晨's avatar 史晓晨

feat:修改ios通知展示;

上级 414a7844
...@@ -178,7 +178,8 @@ userInfo fetchCompletionHandler ...@@ -178,7 +178,8 @@ userInfo fetchCompletionHandler
// 通知打开回执上报 // 通知打开回执上报
[CloudPushSDK sendNotificationAck:extras]; [CloudPushSDK sendNotificationAck:extras];
NSMutableDictionary *result = [[NSMutableDictionary alloc] init]; NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
NSLog(@"Notification, date: %@, title: %@, subtitle: %@, body: %@, badge: %d, extras: %@.", noticeDate, title, subtitle, body, badge, extras); NSLog(@"Notification, date: %@, title: %@, subtitle: %@, body: %@, badge: %d, extras: %@.",
noticeDate, title, subtitle, body, badge, extras);
if (title != nil) { if (title != nil) {
result[@"title"] = title; result[@"title"] = title;
} }
...@@ -200,26 +201,27 @@ userInfo fetchCompletionHandler ...@@ -200,26 +201,27 @@ userInfo fetchCompletionHandler
if (isSendAck) { if (isSendAck) {
[self.channel invokeMethod:@"onNotification" arguments:result]; [self.channel invokeMethod:@"onNotification" arguments:result];
} else { } else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
[self.channel invokeMethod:@"onNotificationOpened" arguments:result]; [self.channel invokeMethod:@"onNotificationOpened" arguments:result];
}); });
} }
} }
-(NSString *)convertToJsonData:(NSDictionary *)dict{ - (NSString *)convertToJsonData:(NSDictionary *)dict {
NSError *error; NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString; NSString *jsonString;
if (!jsonData) { if (!jsonData) {
NSLog(@"%@",error); NSLog(@"%@", error);
}else{ } else {
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
} }
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString]; NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
NSRange range = {0,jsonString.length}; NSRange range = {0, jsonString.length};
//去掉字符串中的空格 //去掉字符串中的空格
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range]; [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
NSRange range2 = {0,mutStr.length}; NSRange range2 = {0, mutStr.length};
//去掉字符串中的换行符 //去掉字符串中的换行符
[mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2]; [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
return mutStr; return mutStr;
...@@ -232,13 +234,15 @@ userInfo fetchCompletionHandler ...@@ -232,13 +234,15 @@ userInfo fetchCompletionHandler
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)( - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(
UNNotificationPresentationOptions))completionHandler { UNNotificationPresentationOptions))completionHandler {
// if(_showNoticeWhenForeground) { // if(_showNoticeWhenForeground) {
// // 通知弹出,且带有声音、内容和角标
// completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
// } else { // } else {
// 处理iOS 10通知,并上报通知打开回执 // 处理iOS 10通知,并上报通知打开回执
[self handleiOS10Notification:notification isSendAck:YES]; [self handleiOS10Notification:notification isSendAck:YES];
// 通知不弹出 // 通知不弹出
completionHandler(UNNotificationPresentationOptionNone); // completionHandler(UNNotificationPresentationOptionNone);
// 通知弹出,且带有声音、内容和角标
completionHandler(
UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert |
UNNotificationPresentationOptionBadge);
// } // }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论