0

I have an the app when notification is fired i get a notification bar when the app is in background ,when i tap on that bar it navigates into tableview of the notification set . When i quit the app from background i am receiving notification but when tap on the bar the app is getting crashed since its not getting indexpath of the tableview.

I am calling this method in didFinishLaunchingWithOptions and didReceiveLocalNotification in AppDelegate.so that when the app is in background by clicking on notification bar app is navigated to appropriate tableview.

raptor
  • 291
  • 1
  • 9
  • 17

2 Answers2

0

UILocalNotification has a userInfo dictionary. There you can store some relavent information for that notification, in your case indexPath

  NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:selectedSymptomIndex,@"selectedSymptomIndex",keyIndexNumber,@"keyIndexNumber", nil];
localNotification.userInfo = userInfo;  

while receiving the notification(in didReceiveLocalNotification) you can retrieve the userInfo dictionary like notification.userInfo. from that you will get selectedSymptomIndex and keyIndexNumber.
Now you can construct the indexPath

NSIndexPath *selectedSymptIP = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
  • Check this out for sending data to notification http://stackoverflow.com/questions/4312338/how-to-use-the-object-property-of-nsnotificationcenter – Radu May 20 '13 at 12:56
  • you have to set the userInfo when you are scheduling notification with the appropriate values like i suggested. Then you can get it back on applicationDidReceiveLocalNotification by accessing the userInfo of received notification... from there you will get the dictionary back.. take the values from dict and whatever you want – Anil Varghese May 21 '13 at 05:48
  • use the same user info that you are used in the scheduleNotification you can more values to that dict,no need to create another one. – Anil Varghese May 21 '13 at 06:09
  • they are in same view controller? just pass the selected indexPath to the scheduleNotification. or [self.tableView indexPathForSelectedRow] may work. Remember you cannot set indexPath directly in userInfo.. set section number and row number separately – Anil Varghese May 21 '13 at 06:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30298/discussion-between-anil-and-raptor) – Anil Varghese May 21 '13 at 06:26
0

Please print your userinfo and see what comes in it. It will be a dictionary and may be possible it has missed something or containing any nil value.

iEinstein
  • 2,100
  • 1
  • 21
  • 32