We've been developing an iOS application (iOS 9+ only) in Swift. We are using VOIP notifications for certain things then use local notifications to actually show the message to the user.
My problem is that when the phone is locked it can take up to 15 seconds for the local notification to actually get displayed, even though I can see my debug output and the code being ran immediately when I expect it.
This is my code for showing the notification:
let notification = UILocalNotification() notification.alertTitle = "Title text.".local notification.alertBody = "Body text." notification.alertAction = "Action".local notification.category = Notification.CallCategory notification.soundName = localNotificationSoundName notification.userInfo = msg.dictionary() UIApplication.sharedApplication().presentLocalNotificationNow(notification)
Other than the delay everything works as expected and when the phone is not locked there is no delay and the notification works as expected.
Any ideas?
EDIT
As a clarification this code is being run inside a switch/case that resides in our implementation of PKPushRegistryDelegate. Specifically within this function:
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!)
Additionally it is worth noting that this not happen on every device. We have one iPhone 6s test device where it happens every time, regardless of how many times we reboot the device, reinstall the app or even upgrade iOS to a newer version. We have a few other test devices where it doesnt happen.
1 Answers
Answers 1
Read this from Apple doc -
Prioritize Remote Notification Delivery
Remote notifications provided by your server to the Apple Notification Service include a variety of elements, including payload data, an expiration date, a priority, and more. Remote notifications support two levels of push priority. One delivers the notification immediately. The other delays delivery of the notification until an energy-efficient time. Unless a notification truly requires an immediate delivery, use the deferred delivery method.
I know your problem is for slow
local notification
but still make sure you have Prioritize remote notification.I have experienced while testing that app has certain delay when using local notifications. Maybe that is how system is designed and not necessarily a flaw. For VOIP case I still think you should have used push notification to notify the call (Maybe you have some internal calculation before making notification). But do check out Facebook messenger app, it looks like it does mix match push / local notification to notify user for calls. Try to observe the delay if any.
Make another simple app which shows Local Notification for same code as above and observe if it too has some delay. For this test don't use remote notification to fire the Local Notification, just test after app launch or something like that. This is to make sure if system is delaying certain apps notification for case immediately after push notification ?
Please try Settings->General->Reset-> Reset Network Settings
ReplyDelete