简体   繁体   中英

VoIP, PushKit and app wake up

I'm developing a VoIP app using PushKit and CallKit. I'm aware that similar questions have been asked quite often on different forums but unfortunately have never really been answered. Also most of these posts are from around 2015 so i assume chances are a lot has been changed in terms of someone might have figured meanwhile how to get this working.

What's working:

When the app is running in foreground or sent to background it receives push notifications using the sandbox server as well is the production server.

I'm on iOS 11 and Xcode 9 and needed to enable the regular push notifications in 'capabilities' as well as manually adding the voip background mode to the info.plist for the delegate methods to get called. Linking CallKit and PushKit alone was not enough to receive notifications. I also enabled Background Audio, Background fetch and Remote Notifications. I also created a background task before doing the push registry registration and i end that task after receiving the push token.

What's not working:

Waking up the app after reboot or force quit on incoming calls.

I see the process launching on incoming calls in the Instruments activity monitor though but it looks like something's not working from there since i don't get the incoming call ui.

Questions:

  1. When the app is not running what's the entry point on an incoming notification? -pushRegistry:didReceiveIncomingPushWithPayload:forType: or maybe (only) -application:didFinishLaunchingWithOptions: ?
  2. I stored my credentials to register with the server in the keychain. is it possible that there's a point during application launch when it's too early to query the keychain for something?

UPDATE:

figured a solution myself. this was more a timing issue between client and server. so this is what worked for me.

  1. send the push from the server which launches the app
  2. give the app some time to launch and reregister at the sip server after receiving the push
  3. send the INVITE the client using the latest registration information

also important is not calling the completion handler on the push notification delegate too early which will put the app back to sleep and the INVITE will never be received.

also maybe helpful and something that would make the scenario a little more forgiving. if your sip server sends the invite a couple of times make sure that on each of them always the latest registration information is being used. meaning.. let's say the first INVITE is sent too early to some outdates registration information and the client still launches trying to update that information on the server... make sure the next one uses the updated information. some sip server simply use the first information available for each iteration. and so you would wait forever without receiving anything on the client.

Every time your app launches, it should instantiate a PKPushRegistry instance and set its delegate. This should happen in response to one of the UIApplication -application:applicationDidFinishLaunching… callbacks, and not (for example) in a view controller's -viewWillAppear/-viewDidAppear callbacks, because only the former is invoked when your app is launched in the background. Some developers have hit bugs in which they only instantiated a PKPushRegistry in a view controller or other code path that is only relevant when an app is launched in the foreground (ie while showing visible UI), so take care that this object is always instantiated regardless of whether it's background or foreground.

Once you create a PKPushRegistry and assign its delegate, it will become eligible to receive delegate callbacks for incoming push notification payloads, and your app should be able to handle these payload(s) and process the incoming call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM