umeng ios推送怎么添加title和内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了umeng ios推送怎么添加title和内容相关的知识,希望对你有一定的参考价值。
可以在Debug模式下输出的logcat中看到Device Token,也可以使用下面的方法来获取Device Token。帮用户确定是没有替换包名导致的错误 附上二个问题的答案:device token获取的办法:String device_token = UmengRegistrar.getRegistrationId(context),说明Device Token为友盟生成的用于标识设备的id,长度为44位,不能定制和修改。同一台设备上每个应用对应的Device Token不一样。
获取Device Token的代码需要放在mPushAgent.enable();后面,注册成功以后调用才能获得Device Token。
如果返回值为空, 说明设备还没有注册成功, 需要等待几秒钟,同时请确保测试手机网络畅通。
关于以上类似的问题,可以试试极光推送,多种消息类型,开发者可以轻松地通过极光发送各个移动平台的系统通知,还可以在控制台编辑多种富文本展示模板; 极光还提供自定义消息的透传,客户端接到消息内容后根据自己的逻辑自由处理。
参考技术A 可以在Debug模式下输出的logcat中看到Device Token,也可以使用下面的方法来获取Device Token。
帮用户确定是没有替换包名导致的错误,附上二个问题的答案
device token获取的办法:
String device_token = UmengRegistrar.getRegistrationId(context)
说明
Device Token为友盟生成的用于标识设备的id,长度为44位,不能定制和修改。同一台设备上每个应用对应的Device Token不一样。
获取Device Token的代码需要放在mPushAgent.enable();后面,注册成功以后调用才能获得Device Token。
如果返回值为空, 说明设备还没有注册成功, 需要等待几秒钟,同时请确保测试手机网络畅通。本回答被提问者采纳 参考技术B 同求 楼主有没有找到解决办法 我是java后台调用的推送 参考技术C
java 后台调用友盟推送 如何设置ios 的 title? - 呆呆的鬼先生i的回答 - 知乎
https://www.zhihu.com/question/277421394/answer/475317557
拿去不谢
IOS 7 通过单击推送通知查看特定视图控制器
【中文标题】IOS 7 通过单击推送通知查看特定视图控制器【英文标题】:IOS 7 view Specific View Controller by Clicking Push Notification 【发布时间】:2014-03-06 12:21:51 【问题描述】:我为我的应用设置了推送通知,这样当我点击推送通知时,应用会转到主控件视图。但是,我想根据添加到应用程序中的内容查看特定的视图控制器。我该怎么做?
我的应用委托代码。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
return YES;
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
const char* data = [deviceToken bytes];
NSMutableString * token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++)
[token appendFormat:@"%02.2hhX", data[i]];
NSString *urlString = [NSString stringWithFormat:@"url"?token=%@",token];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSLog(@"token %@",urlString);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSLog(@"request %@ ",urlRequest);
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSLog(@"data %@",urlData);
// NSLog(@"token ",sendUserToken);
我的 php 推送通知脚本。
<?php
token ="my token"
$payload = '
"aps" :
"alert" :"'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
';
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl', 'local_cert','ck.pem');
stream_context_set_option($ctx,'ssl','passphrase', 'balpad');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);
if(!fp)
print "Failed to connect $err $errstrn";
return;
else
print "notifications sent!";
$devArray = array();
$devArray[] = $deviceToken;
foreach($deviceToken as $token)
$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ',' ',$token)).pack("n",strlen($payload)) . $payload;
print "sending message:" .$payload . "n";
fwrite($fp,$msg);
fclose($fp);
?>
这是我第一次使用推送通知,但我还没有找到合适的解决方案。我找到了一些建议(link1link2),但我发现它们有点令人困惑,我没有任何想法。请有人指导我如何制作这个。
【问题讨论】:
【参考方案1】:我有一个解决方案给你。请参考下面的示例代码:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
// Below Code Shows Message While Your Application is in Active State
NSString *cancelTitle = @"Ok";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"App Start"
message:message
delegate:nil
cancelButtonTitle:cancelTitle
otherButtonTitles: nil];
[alertView show];
[alertView release];
else
// Do stuff that you would do if the application was not active
// Please add your code to go to specific view controller here.
【讨论】:
【参考方案2】:每当我们收到推送通知时,我们都会通过 ios 调用接收通知方法。
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
In this method base on your requirement you can navigate on any view; suppose that you want to navigate on firstviewcontroller, so code is like that:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
// here you need to check in which view controller is right now on screen;
//1. if it is same in which you are then no problem just referesh controller;
//otherwise push to your view controller like following"
firstviewcontroller = [[firstviewcontroller alloc] initWithNibName:@"firstviewcontroller" bundle:nil];
[self.navigationController pushviewcontroller:firstviewcontroller animated:YES];
【讨论】:
【参考方案3】:好的,这样做:
在您的 .php 中添加另一个键,例如:
...
"alert" :"'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff",
"condition" : "viewController1"
...
你可以在那里写任何你想要的。这将告诉您收到推送时要显示的屏幕,它不需要是您的真实控制器的名称,只是一些条件,以便您可以不同的通知
然后像这样覆盖 didReceiveRemoteNotification:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
// Below Code Shows Message While Your Application is in Active State
NSString *strControllerToShow = [[userInfo valueForKey:@"aps"] valueForKey:@"condition"];;
if(condition != nil)
if([condition isEqualToString:@"viewController1"])
// create vc
// set properties
// push it on navigation stack
if([condition isEqualToString:@"viewController2"])
// create vc
// set properties
// push it on navigation stack
...
else
// Do stuff that you would do if the application was not active
// Please add your code to go to specific view controller here.
就是这样……
【讨论】:
小心不要将太多信息放入推送中,Apple可以拒绝它:(以上是关于umeng ios推送怎么添加title和内容的主要内容,如果未能解决你的问题,请参考以下文章