推送通知和查看按钮动作[iphone sdk APNS]

时间:2010-11-30 11:52:30

标签: iphone notifications push apple-push-notifications

我正在为Iphone开发推送通知的应用程序。 在我的应用程序中,我有两个列表视图(UITableView) 第1类为分类列表,第2类为内容列表。 用户单击所需的类别,然后将显示与该类别相关的内容,然后用户将选择内容,内容将显示在详细视图中(通常是UIWebView)。

推送通知已成功进入我的应用程序。 我的要求是: - 点击Push alert的VIEW按钮后,应用程序将直接显示一个特定的 详细视图(UIWebView)[省略类别和内容列表]。 我有类别和内容的唯一ID。 那么请您指导我如何将特定内容与推送通知相关联并直接显示该内容。

谢谢和问候。

1 个答案:

答案 0 :(得分:6)

HI,

我已经解决了这个问题。 这就是我所做的。 当应用程序收到推送通知时,它会在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是服务器端的键集,用于推送通知的有效负载。  你可以在服务器端设置任何密钥。

希望它会对某些人有所帮助。 感谢