识别推送通知信息 [英] Identifying the Push Notification Message
问题描述
在我的项目,我想表现的事件,并通过推送通知提供,但问题是,我能够显示的事件或优惠,而不是两个。有没有什么办法来确定的推送通知信息。这里的code:
- (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO
{
* NSString的消息=零;
ID警报= [USERINFO objectForKey:@警报]; 如果([警报isKindOfClass:[NSString类]){
消息=警报;
}否则如果([警报isKindOfClass:[NSDictionary的类]){
消息= [警报objectForKey:@身体];
}
如果(警告){
UIAlertView中* alertView = [[UIAlertView中页头] initWithTitle:@标题
消息:@AThe消息。委托:自我
cancelButtonTitle:@按钮1
otherButtonTitles:@按钮,零]
[alertView秀]
} * NSString的contentsInfo = [USERINFO objectForKey:@contTag];
的NSLog(@接收到的内容信息:%@,contentsInfo); * NSString的nibName = [AppDelegate中fetchNibWithViewControllerName:@EventsViewController]; EventsViewController * EVC = [[EventsViewController页头] initWithNibName:nibName捆绑:无]; evc.newEvent = YES; [self.navigationController pushViewController:EVC动画:YES]; [UIApplication的sharedApplication] .applicationIconBadgeNumber = [[[USERINFO objectForKey:@APS] objectForKey:@badgecount]的intValue];
}
警报总是带着两个键一的NSDictionary:身体和显示视图。前者的值是警报消息,后者是布尔(假或真)。如果为false,警报的视图按钮不会显示。默认是显示视图按钮,如果用户点击它,启动应用程序。
检查<一个href=\"http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html\"相对=nofollow>文档
要确定消息类型,你可以提供额外的领域里,如描述<一个href=\"http://developer.appcelerator.com/question/66521/how-to-get-access-to-custom-field-in-apple-push-notification\"相对=nofollow>这里
例如:
{APS:{徽章:1,警告:这是我特别的信息!,mycustomvar1:123456,mycustomvar2:一些文本 myspecialtext:这是最好的!,网址:http://www.mywebsite.com}}
In my project I want to show the events and offers through push notification, but the problem is, I'm able to show the events or offers, not both. Is there any way to identify the message of Push notification. Here's the code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *message = nil;
id alert = [userInfo objectForKey:@"alert"];
if ([alert isKindOfClass:[NSString class]]) {
message = alert;
} else if ([alert isKindOfClass:[NSDictionary class]]) {
message = [alert objectForKey:@"body"];
}
if (alert) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"AThe message." delegate:self
cancelButtonTitle:@"button 1"
otherButtonTitles:@"button", nil];
[alertView show];
}
NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
NSLog(@"Received contents info : %@", contentsInfo);
NSString *nibName = [AppDelegate fetchNibWithViewControllerName:@"EventsViewController"];
EventsViewController *evc = [[EventsViewController alloc] initWithNibName:nibName bundle:nil];
evc.newEvent = YES;
[self.navigationController pushViewController:evc animated:YES];
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
}
"alert" is always a NSDictionary with two keys: body and show-view. The value of the former is the alert message and the latter is a Boolean (false or true). If false, the alert’s View button is not shown. The default is to show the View button which, if the user taps it, launches the application.
check the docs
To identify type of the message you can provide additional fields, like described here
Example:
{"aps": {"badge": 1,"alert": "This is my special message!", "mycustomvar1": "123456","mycustomvar2": "some text", "myspecialtext": "This is the best!", "url": "http://www.mywebsite.com"}}
这篇关于识别推送通知信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!