iOS Swift极光推送点击消息推送内容跳转到对应的界面

开发者 2024-9-30 20:42:25 78 0 来自 中国
本人亲测有效!更多交换可以家魏鑫:lixiaowu1129,公重好:iOS过审汇总,一起探究iOS技能!如果你已经集成完了极光,恰好有这个问题不知怎样办理,可以看看这篇文章,这篇是针对长途通知的,当地通知大同小异吧。
根据我项目的要求,极光推送跳转指定页面分为两种环境:app在背景环境和app在杀死的环境下。app在前台跳转页面临时没做过。
杀死app环境

这种环境app是由推送消息叫醒的,app启动就必须触发这个方法:
-(BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions ;
判定app是否是由推送消息叫醒的,看下面:
把这个写在上面的方法中即可。但是偶然间大概会出问题。下面有方法办理。
if (launchOptions) { //是否有推送消息NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; //这是判定app是否是由长途通知启动的   如果由当地通知启动的 则把 UIApplicationLaunchOptionsRemoteNotificationKey 换成 UIApplicationLaunchOptionsLocalNotificationKeyif (remoteNotification) { //是否有长途推送消息[self jumpToViewctroller:remoteNotification]; //这是跳转页面的方法。}}//跳转方法-(void)jumpToViewctrollerNSDictionary *)remoteNotification{//remoteNotification是消息的json格式,跳转指定控制器起首你必要跟背景探讨一下,添加一个字段。我这里添加的是jump,如果是1跳转这个,是2的话跳转谁人等等。if ([[NSString stringWithFormat"%@",remoteNotification[@"jump"]] isEqualToString"1"]) {//这里留意一下。大多数页面都是UINavigationController的子控制器。固然了,在这里你是不能push进去的。必须present进去。此时你大概会问,那存储一个key值present是干什么用的。哈哈,这是告诉你要跳转的控制器,我是被present进来的。以是我返回的时间你也要把我diss归去。同时你也要扫除它。/*控制器的返回方法。if ([[[NSUserDefaults standardUserDefaults] objectForKey"present"] isEqualToString"1"]) {[self dismissViewControllerAnimated:YES completion:^{[[NSUserDefaults standardUserDefaults] setObject"" forKey"present"]; // 这里最好完全扫除它。}];}else{[self.navigationController popViewControllerAnimated:YES];}*/DelivedViewController *VC = [DelivedViewController new];[[NSUserDefaults standardUserDefaults] setObject"1" forKey"present"] ;[[NSUserDefaults standardUserDefaults] synchronize];UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:VC];[self.window.rootViewController presentViewController:na animated:YES completion:nil];}}以上就是app未运行的环境下跳转页面的。 留意:  前面说了判定是否有推送消息大概有问题。我碰到的问题就是 步伐奔溃。可以让它延长实验,方法如下:
-(BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions { // 忽略 。。。。。。[self performSelectorselector(sendNotation withObject:launchOptions afterDelay:1.5];return YES;}-(void)sendNotationNSDictionary *)launchOptions{if (launchOptions) {NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];if (remoteNotification) {[self jumpToViewctroller:remoteNotification];}}}如许就ok了。
二,app在背景运行环境。

这种环境就非常简单了。 上代码!
// iOS 10 Support  步伐在背景时收到通知,点击通知栏进入app
- (void)jpushNotificationCenterUNUserNotificationCenter *)center didReceiveNotificationResponseUNNotificationResponse *)response withCompletionHandlervoid (^)())completionHandler {// RequiredNSDictionary * userInfo = response.notification.request.content.userInfo;if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {//UNPushNotificationTrigger 长途(通知范例)[JPUSHService handleRemoteNotification:userInfo];//userInfo消息数据,包含jump。if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive ) {[self jumpToViewctroller:userInfo];[UIApplication sharedApplication].applicationIconBadgeNumber = 0; //当地消息清0[JPUSHService setBadge:0];//极光消息清0}}completionHandler();  // 体系要求实验这个方法}- (void)applicationUIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {// Required, iOS 7 Support[JPUSHService handleRemoteNotification:userInfo];if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive ) {[self jumpToViewctroller:userInfo];[UIApplication sharedApplication].applicationIconBadgeNumber = 0;[JPUSHService setBadge:0];}completionHandler(UIBackgroundFetchResultNewData);}本文由mdnice多平台发布
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-11-23 16:10, Processed in 0.124221 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表