推送通知和查看按钮操作[iPhone的SDK APNS] [英] Push notification and view button action[iphone sdk APNS]

查看:95
本文介绍了推送通知和查看按钮操作[iPhone的SDK APNS]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的iPhone推送通知启用的应用程序。
在我的应用我有两个列表视图(UITableView的)
对于第一个类别列表和第二个是内容列表。
用户点击所需的类别,然后与该类别中的内容则显示用户选择的内容,其内容将显示在详细视图(通常一个UIWebView)。

I am developing a Push Notification enabled application for Iphone. In My application I have two List View (UITableView) 1st for Category List and the 2nd is Contents List. User clicks the desired category then the contents related to that category will be displayed then user will choose the contents and the contents will be displayed in detail view(generally a UIWebView).

推送通知已成功在我的应用程序来。
我的要求是: -
按下警报VIEW按钮被点击后,应用程序将直接显示特定
详细信息视图(UIWebView中)[省略的类别和内容列表。
我有类别和内容的唯一ID。
所以,请你指导我如何与一个特定的内容与推送通知,并直接显示该内容。

Push notification is successfully coming in my application. My requirement is:- After VIEW button of Push alert is clicked application will directly display a particular detail view (UIWebView)[Omitting category and contents list]. I have a unique ID for category and contents. So will you please guide me how to relate a particular content with Push Notification and directly display of that content.

感谢和问候。

推荐答案

您好,

我已经解决了这个问题。
这就是我所做的。
当应用程序接收推送通知,它存储在launchOptions NSDictionary的通知。

I have solved the problem. This is what I have done. When application received push notification, it stored notification in 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是服务器端的推送通知有效载荷的一个关键集。
 ü可以设置在服务器端的任意键。

NOTE: Here contTag is a key set in server side for pay load of push notification. U can set any key in server side.

希望这将有助于一些身体。
谢谢

Hope it will help some body. Thanks

这篇关于推送通知和查看按钮操作[iPhone的SDK APNS]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆