Push notification and view button action[iphone sd

2019-03-22 08:37发布

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).

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.

Thanks and regards.

1条回答
Viruses.
2楼-- · 2019-03-22 09:19

HI,

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
}

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

查看更多
登录 后发表回答