美文网首页iOS学习iOS开发精选Obj-C
友盟推送跳转到指定页面

友盟推送跳转到指定页面

作者: 韦德460 | 来源:发表于2017-04-18 00:01 被阅读797次

设置界面添加自定义参数 见下图
key:url
value:具体的url(与openURL一个意思)

友盟添加url

具体代码

//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于前台时的远程推送接受
        //关闭友盟自带的弹出框
        [UMessage setAutoAlert:NO];
        //必须加这句代码
        [UMessage didReceiveRemoteNotification:userInfo];
    }
    else{
        //应用处于前台时的本地推送接受
    }
    //当应用处于前台时提示设置,需要哪个可以设置哪一个
    completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}
//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于后台时的远程推送接受
        //必须加这句代码
        [UMessage didReceiveRemoteNotification:userInfo];
        [self handleUMPush:userInfo];
    }
    else{
        //应用处于后台时的本地推送接受
    }
}
// 处理友盟推送
- (void)handleUMPush:(NSDictionary *)userInfo
{
    if (userInfo)
    {
        if ([userInfo containsObjectForKey:@"url"])
        {
            NSString *urlStr = userInfo[@"url"];
            urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            // 这里是根据路由机制来跳转页面的,也可以使用其他方式
            openURL(urlStr);
        }
    }
}


可参考友盟官方demo



强烈推荐:超简单!!! iOS设置状态栏、导航栏按钮、标题、颜色、透明度,偏移等

https://github.com/wangrui460/WRNavigationBar
https://github.com/wangrui460/WRNavigationBar_swift



欢迎关注我的微博:wangrui460

相关文章

网友评论

  • ttdiOS:你好,问一下,当需要把 NSDictionary * userInfo每个推送过来的字典存起来,该怎么操作???进行本地数据库缓存userInfo,求指教
    我用的是YTKKeyValueStore,存数组 NSMutableArray *msgDataList;,在iOS10新增:处理前台收到通知的代理方法里写 [self.pushDataList addObject:userInfo];
    [TTMsgDataCache dataCache].msgDataList = self.pushDataList;
    但是这样的话第二次运行xcode会覆盖第一次的数据库

本文标题:友盟推送跳转到指定页面

本文链接:https://www.haomeiwen.com/subject/kibxzttx.html