【问题标题】:Push notification and view button action[iphone sdk APNS]推送通知和查看按钮操作[iphone sdk APNS]
【发布时间】:2011-05-17 20:06:18
【问题描述】:
我正在为 Iphone 开发支持推送通知的应用程序。
在我的应用程序中,我有两个列表视图(UITableView)
类别列表第 1 位,内容列表第 2 位。
用户点击想要的分类,会显示与该分类相关的内容,然后用户选择内容,内容将显示在详细视图(一般是UIWebView)中。
推送通知已成功进入我的应用程序。
我的要求是:-
点击 Push alert 的 VIEW 按钮后,应用程序将直接显示特定的
详细视图(UIWebView)[省略类别和内容列表]。
我有一个类别和内容的唯一 ID。
那么请您指导我如何将特定内容与推送通知相关联并直接显示该内容。
感谢和问候。
【问题讨论】:
标签:
iphone
notifications
push
apple-push-notifications
【解决方案1】:
嗨,
我已经解决了这个问题。
这就是我所做的。
当应用程序收到推送通知时,它会将通知存储在 launchOptions NSDictionary 中。
/* Push notification received when app is not running */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *params=[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"contTag"];
if ([params length] > 0 ) {//app launch when VIEW button of push notification clicked
//do some processing
........
WebViewController *webViewController =
[[WebViewController alloc] initWithNibName:@"WebView" bundle:[NSBundle mainBundle]];
// Put your custom code
[[self navigationController ] pushViewController:webViewController animated:YES];
[window addSubview:navigationController.view];
/* Remote Notification Received while application was open. */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"remote notification: %@",[userInfo description]);
NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
NSLog(@"Received contents info : %@", contentsInfo);
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alert = [apsInfo objectForKey:@"alert"];
NSLog(@"Received Push Alert: %@", alert);
NSString *sound = [apsInfo objectForKey:@"sound"];
NSLog(@"Received Push Sound: %@", sound);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//-----------------------APNS HANDLE----------------
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive){
NSLog(@" It is in active state");
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
}
else {
if ([contentsInfo length] > 0 ) {
// Do whatever u want for push notification handle
}
注意:
这里 contTag 是服务器端为推送通知的有效负载设置的键。
你可以在服务器端设置任何键。
希望对身体有所帮助。
谢谢