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

查看:22
本文介绍了推送通知和查看按钮动作[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.

谢谢和问候.

推荐答案

HI,

我已经解决了这个问题.这就是我所做的.当应用收到推送通知时,它会将通知存储在 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天全站免登陆