0

In my app, user can join to remote events. When the user joins an event, I create an event in native iOS calendar. I know that I can edit and delete that event from my app when the app is running.

Now I have a requirement to edit or delete the above mention event based on a push notification. That means, when ever a change happens to the remote event, my app receive a push notification. So, I want to know, can I edit or delete the native calendar event when ever the push notification received(It can be app running in background or killed).

smartsanja
  • 4,413
  • 9
  • 58
  • 106

2 Answers2

0

Using APN (as opposed to PK), you need to enable background notifications in your app's entitlements. Send the notifications with content-available : 1 in the aps dictionary of the payload. Implement the new(er) delegate method for handling background processing of notifications in the app delegate. Pray that iOS chooses to run the app in the background often enough to make the feature not feel buggy.

There is no sure-fire to gain processing time when your app is in the background or not running. Notifications can help, but Apple explicitly states there are no guarantees. One known scenario where iOS will not launch the app to process a notification is when the app was most recently killed by the user (swiping up in the task switcher).

Push Kit messages are guaranteed to wake or launch the app in the background, but the app must be a VoIP app to use them.

Also, if you go this route, be aware that your app will behave differently when launched directly in the background. You can't assume that a launch will always end with the app in the Active state.

Avi
  • 7,469
  • 2
  • 21
  • 22
  • I already have enabled remote notifications in background modes. But as per your answer, I understand that app should wakeup in order to do the background process and which is not guaranteed to happen. Also, that means I cannot do this when the app is killed. Also, how about the app is running in background but phone is locked. – smartsanja Sep 21 '16 at 05:32
  • If the app is killed, it _may_ be launched to process the notification. Or it may not. I don't know if the event API is available while a device is locked. I'm familiar with the related concepts, but not the details. – Avi Sep 21 '16 at 05:43
0

Yes, you can edit and delete. When you are getting silent push notification your app gets invoke in background. Even we can do activity with SQLite database as well.

So once you get silent push notification then you schedule local notification and notify user. your app will be invoke upto your local notification sound plays ( Max 30 seconds ).

You can also perform further UI and logic related things when user tap on local notification or buttons of local notification.

If you keep your local notification object in NSUserDefault, So if your device gets restart still you can have local notification object from NSUserDefault in didFinishLaunchingWithOptions and do further things.

Hasya
  • 9,792
  • 4
  • 31
  • 46