友盟推送
推送不好用解决办法:
-
检查device_token。同一部测试机跑bundle id不同的程序所产生的device_token是不同的。
-
检查appkey填写是否对应正确
-
卸载应用重新运行。
正确运行控制台会输出:
设置友盟推送后台
-
后台下,选中测试模式 -> 添加测试设备 -> 填入上面获得到的deviceToken
-
再在测试模式下(添加测试设备上面)选中添加测试消息。
填入消息描述,内容,选中全部用户,点击提交,即可完成推送的初始测试设置。手机端可以收到推送信息。
更改app前台状态下通知弹出样式
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
此方法为:当你的app远程通知已经收到的时候进行调用
因为友盟自带的alertView是默认开启的
需要使用
[UMessage setAutoAlert:NO];
关闭友盟自带的弹出框
以避免自定义的alertView和友盟提供的alertView冲突。
自定义alertView
- 判断app是否处于前台
[UIApplication sharedApplication].applicationState == UIApplicationStateActive
-
处于前台状态下
UIAlertController *alertViewController = [UIAlertController alertControllerWithTitle:@"消息提醒" message:@"您有一条新通知" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"稍后" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"立即查看" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertViewController addAction:okAction]; [alertViewController addAction:cancleAction]; [self.window.rootViewController presentViewController:alertViewController animated:YES completion:nil];
###生产环境和开发环境测试相关问题
因为在开发环境和生产环境下device_token是不同的,所以无法使用开发下的device_token来进行生产环境测试。一般开发环境下测试没问题,在生产环境也没问题。
官网给出的解释[iOS 友盟推送 app没上线 能测试生产环境吗](http://bbs.umeng.com/thread-15000-1-1.html)
###设置别名,可以按别名推送给部分用户
//友盟注册用户和别名
[UMessage addAlias:@“用户ID” type:@"别名" response:^(id responseObject, NSError *error) {
}];
网友评论