0

I am new in iOS and I am working on push notification. I have done with this by parse.com and it's working fine.

My problem is:

I have two UIViewController. In first ViewController a web service is called in viewDidLoad method and fetch student data from server and display on tableview.

Then I select any student in tableview so it will navigate on second detailviewcontroller where student details will be displayed.

Now I pressed home button and my application goes in background mode and the push notification is arrived.

Now I tap on application icon instead of notification view to show the updates.

Can anybody help me how can I handle this scenario because when user tap on application icon it will directly navigate on student detail view. How can I handle this push notification and update the student tableview?

halfer
  • 19,824
  • 17
  • 99
  • 186
Bandish Dave
  • 791
  • 1
  • 7
  • 27
  • fyi: seems like you are dealing with sensitive (student) information, in US just recently schools are being discouraged/prohibited to use apps that utilize cloud (which parse.com uses) due to FERPA/HIPAA, you need to use dedicated server. – Boris Gafurov Jul 01 '15 at 19:41
  • @BorisGafurov thank you for giving this information. – Bandish Dave Jul 01 '15 at 20:10

3 Answers3

1

content-available flag is what you need. Append it to your payload, handle application:didReceiveRemoteNotification:fetchCompletionHandler: and you will be able to catch all push notifications. Take a look at my answer to the same question for more details.

P.S. There is no way if your app is force closed. If your app is running - you can process all the notifications

Community
  • 1
  • 1
Sega-Zero
  • 3,034
  • 2
  • 22
  • 46
  • 1
    Comments deleted as they were definitely **not** constructive. – ChrisF Jun 26 '15 at 21:47
  • 1
    Also if you think you've found a duplicate please flag it as such rather than posting an answer that's essentially a link to the other question. – ChrisF Jun 26 '15 at 21:48
0

ok, may be try this when app opens:

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    int i=[UIApplication sharedApplication].applicationIconBadgeNumber;
    //if i!=0 you got some notifications - fetch data from server and refresh array with data
}
Andrew Lygin
  • 6,077
  • 1
  • 32
  • 37
Boris Gafurov
  • 1,427
  • 16
  • 28
  • thank you for replaying but my question is something differnet.. i do not want to go on first screen when app is become active but want to update the student table array or data? – Bandish Dave Jun 26 '15 at 19:41
  • assuming your app gets badged when push arrives - see my edited answer – Boris Gafurov Jun 26 '15 at 20:24
0

While I like the workaround with reading badge number, I'd try to be explicit about the problem, if you can not implement synchronising API call that would bring delta changes since the last request, you can use push notifications to solve the problem.

  1. When your app is simply in the background, your AppDelegate will get called with - application:didReceiveRemoteNotification:
  2. If you app is not running you can send push notifications triggering your app to process, the delegate you'll get is - application:didReceiveRemoteNotification:fetchCompletionHandler:

In both cases you will need to tweak the JSON payload to launch the app in the background if not already running.

In both cases you want to persist the "unprocessed" notifications. If you want to persist only identifiers or any other small chunk of information I'd probably take a look at NSUserDefaults.

If data is substantial, or if you want to fetch objects from the network, a database or CoreData (or even Parse.com local storage solution) should be a more suitable approach.

it is important to remember to purge the local queue of unprocessed notifications you created, once your app is actually launched.

Hope it helps

Update @Sega-Zero mentions the name of the field for JSON you should include in your payload

Sash Zats
  • 5,376
  • 2
  • 28
  • 42