Running app using push notification in iOS - ios

Can the iOS push notifications be used to automatically execute the attached application somehow (without user action)?

Actually no, when your app is in terminated (killed) state and you receive push notification, then app doesn't get wake up in back ground and your any piece of code will not get executed.
If your app is VOIP based or in particular App Store category ( permission had to be taken in advance from Apple development ) then you can you push kit ( silent notification ).
Using local notification based on your push kit payload. Unless sound file plays. Your app will get wake up background and you can execute your piece of code( max for 30 seconds) till sound file plays.

Related

Reliable delivery of iOS VOIP Push Notifications

Like many here, I was looking for a reliable way to deliver push notifications to an app for background processing. I finally decided to use PushKit and all works well and the app was accepted into the AppStore, even though it's not a VoIP application. I'm using the AWS SNS (Simple Notification Services) to handle the backend push processing. However, even VoIP notification delivery will be throttled by iOS if you send excessive push notifications. As a simple test, I can send several VoIP notifications over 2 - 3 min and they will deliver promptly and processed by the app in the background. After I wait about 10 minutes (after locking the iPad and waiting for the application to be put to sleep by iOS) a subsequent VoIP push won't be delivered promptly by iOS. AWS is pushing the notification, but iOS is not delivering it to the app. I know this because as soon as I plug in the device, the notification is processed by the application. As an aside, if the device is left plugged in, all notifications deliver and process promptly.
So my question is this: Have others noticed this behavior with VoIP pushes also? Even though the iOS docs indicate that VoIP pushes are delivered immediately, it appears that iOS does throttle them if it considers the pushes "excessive" over some period of time.
I guess, When you keep your app in background then you receives push notification. but when your app is in terminated then don't receive push notification.
Possibly your app gets crash when it is in killed ( terminated ) state.
Pushkit silent notification is always with higher priority and works well all the time.
Try below things to find out cause and solution.
(1) Debug your app in killed ( terminated ) state, like app is crashing or not
(2) Send silent notification with simple php code using pem and certificates ( Both case background and killed ( terminated ) )
(3) Check pushkit integration steps, if your app is not registered for VOIP, then it would not receive silent notification.
Debug pushkit notification in terminated state
Put debug pointer on delegate methods
Go to edit scheme
Select run option then Launch -> Wait for executable to be launched
Send push kit payload from back end
Once you get payload on device
it will automatically invoke and debug pointer will invoke at delegate methods.
Refer some material

iOS 10 Remote Notifications When App Not Running

When I receive a remote notification I updated a counter that I save to UserDefaults and I also show a local notification. Everything works as expected when the app is in the foreground, background, and suspended states Ref. When the app is in the Not Running state my counter is not updated nor is my local notification shown.
It is my understanding that I should be able to receive and process Remote Notifications while the app is completely off. A few articles online claim that when a Remote Notification arrives while in the Not Running state that the application:didFinishLaunchingWithOptions: should be called followed by application: didReceiveRemoteNotification:fetchCompletionHandler: but in my case it is not.
Is it possible to receive remote notifications while in Not Running state?
If your app is a VoIP app and you are using VoIP pushes through PushKit then a push notification will launch your app from the terminated state in order to deliver the notification. If you are using standard push notifications then your app will not receive the notification if it is terminated. You can include an alert text with a 'silent' notification that will be displayed to the user in the event that your app is terminated in order to prompt them to launch your app.
First of all, it sounds like you have a silent notification set up. Once you add alert data to your push notification (information like the title, body etc.. you can find more on that here), it'll start to display on the lock screen.
Second, it's not possible for your application to launch from a push notification, silent or otherwise, if it's in the Not Running state. The documentation on this is actually incorrect, as it states that the application will only not be launched if the user has quit the app. However, this actually also applies for any circumstance under the not-running state, for example if your app has never been launched since installation/rebooting, or if it was quit due to memory (a fairly common occurrence - iOS purges apps which haven't been run recently as required).
did you check this mark when app is background?

Handle remote notifications when phone is locked/app not running

I'm using a combination of Firebase and Batch for a chat like application.
When a push notification is received the app should be able to perform some tasks based on the data received in the notification.
From my understanding this can only be done in app states suspended -> active and not terminated.
I have it working when the app is in the foreground and also when closing the app via home button.
Should the device be locked however, didReceiveRemoteNotification:fetchCompletionHandler: is never called. At least not until the user interacts with the notification from notification center.
Is this correct? Can no work be done on a remote notification if the device is locked?
I have all the appropriate entitlements and "content-available":1 set correctly.
Is there another way that I can wake the app up from a notification and do a few background tasks? I also tried using Notification Service Extension but had the same issue with nothing happening while the device was locked.

Invoke iOS app at specific time and date

I want my iOS app to know when a specific date and time arrives without any failure. Now this time can be in days/weeks/months and my application can be in backgorund Or in terminated state.
So there are following options:
a. Local notification -- but it doesn't notify when my app is in background.
b. Silent Push notification -- it will work but it requires us to built server for same.
Is there any other option with which we can achieve same?
There is no way you can achieve this,
Your options are :
1) By using local notification like schedule notification on particular time and store that time and related activity in userdefaults. whenever app state changes to background to foreground in appdelegates - (void)applicationDidBecomeActive:(UIApplication *)application method write a code to handle desired functionality.
2) Silent push notification, which works only when your app is in background/minimized state. Once your app is Killed(swipe up from multitasking), even silent push notification cannot wake up your app.
3) To overcome the limitations of silent push notifications, Apple introduced Pushkit Notifications in iOS8, for voip apps like whatsapp, Skype, etc, in which push kit notification once received, wakes up your app even it is terminated or not running in background. Again you cannot use Pushkit unless you are actually using voip.
No. Sounds like you have to use push notifications.
This is the only thing that would work if your app is terminated.

How to show a local notification alert or a local notification banner when App is closed

How to show a local notification alert or a local notification banner when App is closed (either in the background or foreground), I can only modify the badge number when the app is closed...
You will not be able to present notifications while the app is in the background unless you implement Push Notifications with APNS and use UIRemoteNotification. Based on your experience and the scope of the project, it may be a bit complicated, but here is a good reference on getting started:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
As of the writing of this answer, using iOS 8.4 (soon iOS9), you CAN
Display UILocalNotifications when the app is closed
Display push notifications whenever you want.
If your local notification is scheduled, it WILL fire, wheter or not the app is foreground/background/killed.
So now, your problem is this one : How do I schedule a local notification when the app is forground/background/kill ?
It's easy, in the Appdelegate, you can simply follow any tutorial and type your code there, it's pretty straightforward. The only different thing is, if the app is killed, you can't execute code unless the app is awaken with a push notification. And that's where the remote push notifications are useful, you can awaken your app (and execute code) with a push notification and do whatever you need from here on out.
You could :
- Display the content you want with the actual push notification. " You have 1 new message! "
- Send a "silent" push notification (invisible by the user) that still awakens your app, and execute code there, for example to update data or modify stuff in your app in general. If I'm not mistaken you're only allowed 15 minutes of work and a certain amount of data transfer when the app is awaken like that, but that has to be verified.
I hope I helped :)

Resources