更换阿里推送,消息页面,以及部分bug修复

This commit is contained in:
wbzhan
2019-06-15 17:44:25 +08:00
parent 1ff1ff84b1
commit 5a10dfa182
13 changed files with 97 additions and 98 deletions
+46 -29
View File
@@ -8,6 +8,7 @@
#import "AppDelegate+AliPushConfig.h"
#import <objc/runtime.h>
#import "IfishMessageViewController.h"
static const void *NotificationCenterKey = &NotificationCenterKey;
@implementation AppDelegate (AliPushConfig)
- (UNUserNotificationCenter *)notificationCenter {
@@ -255,8 +256,18 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
NSString *body = [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding];
NSLog(@"\n ====== Receive message title: %@, content: %@.", title, body);
NSLog(@"\n ====== 当前线程 %@",[NSThread currentThread]);
[CommonUtils showAlerWithTitle:IsEmptyStr(title)?@"新消息":title withMsg:body];
// [CommonUtils showAlerWithTitle:IsEmptyStr(title)?@"新消息":title withMsg:body];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:IsEmptyStr(title)?@"新消息":title message:body preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//进入消息列表页面
IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController];
vc.hidesBottomBarWhenPushed = YES;
[vc.navigationController pushViewController:message animated:YES];
vc.hidesBottomBarWhenPushed = NO;
}];
[alertController addAction:alertAction];
[[CommonUtils appRootViewController] presentViewController:alertController animated:YES completion:nil];
}
#pragma mark —页面跳转(暂时不做处理)
@@ -284,28 +295,16 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
NSString *userAction = response.actionIdentifier;
// 点击通知打开app
// 点击通知打开appapp处于后台)
if ([userAction isEqualToString:UNNotificationDefaultActionIdentifier]) {
NSLog(@"\n ====== User opened the notification.");
// 处理iOS 10通知,并上报通知打开回执
[self handleiOS10Notification:response.notification];
[self handleiOS10Notification:response.notification isActive:NO];
}
// 通知dismisscategory 创建时传入 UNNotificationCategoryOptionCustomDismissAction 才可以触发
if ([userAction isEqualToString:UNNotificationDismissActionIdentifier]) {
NSLog(@"\n ====== User dismissed the notification.");
}
// NSString *customAction1 = @"action1";
// NSString *customAction2 = @"action2";
//
// // 点击用户自定义Action1
// if ([userAction isEqualToString:customAction1]) {
// NSLog(@"User custom action1.");
// }
//
// // 点击用户自定义Action2
// if ([userAction isEqualToString:customAction2]) {
// NSLog(@"User custom action2.");
// }
completionHandler();
}
/**
@@ -318,7 +317,7 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
NSLog(@"\n ====== App 处于前台时收到通知 (iOS 10+ )");
// 处理iOS 10通知,并上报通知打开回执
[self handleiOS10Notification:notification];
[self handleiOS10Notification:notification isActive:YES];
/*
处理完成后调用 completionHandler ,用于指示在前台显示通知的形式
@@ -345,7 +344,7 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
/**
* 处理App 处于前台时收到通知 (iOS 10+ )
*/
- (void)handleiOS10Notification:(UNNotification *)notification {
- (void)handleiOS10Notification:(UNNotification *)notification isActive:(BOOL)isActive{
UNNotificationRequest *request = notification.request;
UNNotificationContent *content = request.content;
@@ -370,9 +369,29 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
// 通知打开回执上报
[CloudPushSDK sendNotificationAck:userInfo];
NSLog(@"\n ====== App 处于前台时收到通知 (iOS 10+ ) Notification, == date: %@, == title: %@, == subtitle: %@, == body: %@, == badge: %d, == extras: %@.", noticeDate, title, subtitle, body, badge, extras);
[CommonUtils showAlerWithTitle:IsEmptyStr(title)?@"新通知":title withMsg:body];
//App处于前台
if (isActive) {
NSLog(@"\n ====== App 处于前台时收到通知 (iOS 10+ ) Notification, == date: %@, == title: %@, == subtitle: %@, == body: %@, == badge: %d, == extras: %@.", noticeDate, title, subtitle, body, badge, extras);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:IsEmptyStr(title)?@"新通知":title message:body preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//进入消息列表页面
IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController];
vc.hidesBottomBarWhenPushed = YES;
[vc.navigationController pushViewController:message animated:YES];
vc.hidesBottomBarWhenPushed = NO;
}];
[alertController addAction:alertAction];
[[CommonUtils appRootViewController] presentViewController:alertController animated:YES completion:nil];
}else{
NSLog(@"\n ====== App 处于后台时收到通知 (iOS 10+ ) Notification,点击通知打开应用, == date: %@, == title: %@, == subtitle: %@, == body: %@, == badge: %d, == extras: %@.", noticeDate, title, subtitle, body, badge, extras);
//进入消息列表页面
IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController];
vc.hidesBottomBarWhenPushed = YES;
[vc.navigationController pushViewController:message animated:YES];
vc.hidesBottomBarWhenPushed = NO;
}
}
@@ -417,14 +436,12 @@ static const void *NotificationCenterKey = &NotificationCenterKey;
*/
} else if (application.applicationState == UIApplicationStateInactive) {
// // 程序处于后台 做相应的处理
// for (NSString *tfStr in userInfo) {
// if ([tfStr isEqualToString:@"careline"]) {
// JumpViewController *_viewController = [[JumpViewController alloc]init];
// UINavigationController *nav= (UINavigationController *)self.window.rootViewController;
// [nav pushViewController:_viewController animated:YES];
// }
// }
// //点击通知打开app,则跳转到消息列表
// IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
// UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController];
// vc.hidesBottomBarWhenPushed = YES;
// [vc.navigationController pushViewController:message animated:YES];
// vc.hidesBottomBarWhenPushed = NO;
}
}
+6
View File
@@ -529,6 +529,12 @@ CGAffineTransform GetCGAffineTransformRotateAroundPoint(float centerX, float ce
while (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
if ([topVC isKindOfClass:[UITabBarController class]]) {
topVC = [(UITabBarController *)topVC selectedViewController];
}
if ([topVC isKindOfClass:[UINavigationController class]]) {
topVC = [(UINavigationController *)topVC topViewController];
}
return topVC;
}
+(void)showAlerWithTitle:(NSString*)title withMsg:(NSString*)msg{