iOS PushKit ring phone - ios

I'm developing a VoIP app with Apple's PushKit. I am able to receive notifications when the app is in background or even when it's not running. However, I don't know how to turn on the display and ring the phone when it's necessary, like in case of incoming VoIP call.

You can schedule local notification, with push kit or anything never you app will come foreground, never phone will turn on.
With use of local notification you can set sound file for 30 seconds.
You can repeat at every 30 seconds until user act on local notification.
Local notification could have action buttons.

Related

How can a iOS app push a local notification after killed when the wifi and cellular is closed?

I discover an app, called 2n mobile key. I have some doubts about this app. First, I close the wifi, cellular, and switch on the Bluetooth, then I open the app, everything is fine. And then, I kill the app, and open the control center, close the Bluetooth, I got a local push(I have closed the wifi and cellular). I don't know how the app can push the local notification. I doubt the app isn't killed, it is still alive in the background. But, how can it do it?
The notification feature is called "notification extension", so I think it is kind of alive in the background or we can say alive in the system.
Local Notification should be registered and scheduled after getting permission granted.
Application can schedule local notification for delivery to user even though wifi or cellular have turned off. because notification should be delivered to user from iOS (Operating System)
Documentation
Local notifications give you a way to alert the user at times when your app might not be running. You schedule local notifications at a time when your app is running either in the foreground or background. After scheduling a notification, the system takes on the responsibility of delivering the notification to the user at the appropriate time. Your app does not need to be running for the system to deliver the notification.
If your app is not running, or if it is in the background, the system displays local notifications directly to the user. The system can alert the user with an alert panel or banner, with a sound, or by badging your app’s icon. If your app provides a notification content app extension, the system can even use your custom interface to alert the user. If your app is in the foreground when a notification arrives, the system gives your app the opportunity to handle the notification internally.
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW5

iOS: open the app (foreground, background, closed) when a notification is received

I'm a manufacturer of intrusion alarm systems. Now I'd like to send an alarm (a very critical event) to the mobile phone of the user. However it's not acceptable to have a "standard" notification in the tray bar, because the user could ignore it at first. Or another notification could stop my notification.
I'd like to mimic the behaviour of the phone when an incoming call arrives: custom ringtone starts playing for many seconds, the display backlight activates, the vibration starts and so on. Only when the user taps something the ringtone should stop (or after many seconds or minutes).
I think the best method to send messages to a mobile device is through push notifications. However I don't know if the push notification could wake my app, even if it is in background or stopped.
It seems only apps targeting VoIP application can behave in this way. However my app isn't a real VoIP app, so there's a possibility Apple will not accept it.

Running app using push notification in 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.

Pushkit VoiP push notifications wake up app execution time

When I receive VoIP push notification while app is removed from the background (using developer APNS), my app wakes up for like 10 minutes.
When I do the same thing, just this time using production APNS, my app wakes up for 8-10 seconds.
What's the trick there? Why production version of the application can't be woken up for at least 30 seconds? Is there any way to extend wake up time, since 10 sec is not eough for all work I have to do?
EDIT
At the end background time wasn't problem. My app was crashing when completely removed form background and woken up by voip notif. I was thinking that it wasn't crash but limited execution time. When I fixed that crash everything was working as it should.
If you want to invoke your app in background while app is in terminated state. Then you can keep Local notification based on pushkit payload.
Also keep sound file in local notification.
So your app will be active in background even if app is been terminated.
App will be active upto local notification sound plays (Max 30 seconds).
Within that duration achieve your things.
Note Your app must have valid category and permissions from Apple to consume pushkit silent notification. Because pushkit is strongly recommended for VOIP based apps only. If your app is not VOIP based then contact Apple for required permission.
Refer pushkit example if you are not aware.
https://github.com/hasyapanchasara/PushKit_SilentPushNotification

Notify video chat application when app is terminated

Is there any way to notify my video chat application that there is an incoming video call when the app is in the terminated state? (Like an Android background service.)
I notify of incoming calls via socket when the application is in the running and background states.
App that are using VoIP are treated differently by apple and have more privilieges. In the past, that meant keeping a permanent connection to the server to get notified when a call occurs.
This was not very efficient in terms of energy saving.
Since iOS8 it is recommanded to use PushKit (the push notification API) to notify your user when a call occurs. Apps with VoIP privileges will be notified on the spot and that can wake up your app whatever the state it's in.
Here are the world from apple :
Instead of persistent connections, developers should use the PushKit
framework—APIs that allows an app to receive pushes (notifications
when data is available) from a remote server. Whenever a push is
received, the app is called to action. For example, a VoIP app could
display an alert when a call is received, and provide an option to
accept or reject the call. It could even begin taking precursory steps
to initiate the call, in the event the user decides to accept.
https://developer.apple.com/library/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html
Get pushkit payload
Implement pushkit at ios code side
Once you receive silent notification
Schedule local notification
Keep important information in local notification's userinfo
Also keep local notification object in NSUserDefault
If your device gets restart then you can retrieve localnotification userinfo from NSUserDefault object
Once you get silent notification your socket will get active upto your local notification sound plays ( Max 30 seconds )
If you want incoming call ringing more than 30 seconds then server has to send silent notification at each 30 seconds
Delete previous object and reschedule latest on local notification
Let me know if you need any help in push kit implementation.

Resources