I have developed the iPad app which uses apple push notification. Push notification delivering works fine in all the scenario except when the iPad device is locked and notification is delivered. In this scenario it behaves weirdly and opens the app when you slide to unlock the device without touching the alert/banner. Its happening in iOS versions 4.3, 5.1 and also in 6.0
In apple document they have mentioned as below:
http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html
iOS Note: If the user unlocks the device shortly after a remote-notification alert is displayed, the operating system automatically triggers the action associated with the alert. (This behavior is consistent with SMS and calendar alerts.) This makes it even more important that actions related to remote notifications do not have destructive consequences. A user should always make decisions that result in the destruction of data in the context of the application that stores the data.
what is the action associated with alert?
the operating system automatically triggers the action associated with the alert
And also I wanted understand what is the default behavior in this scenario?
Any help is appreciated and thanks in advance.
It is not behaving weirdly, as that is the default behaviour. When your notification lights up the screen, the 'slide to unlock' changes into 'slide to view', which will open your app and execute the action related to your notification.
The default action is that nothing happens if you do not specify anything to happen.
For handling a notification (which is the action associated with the alert) please refer to the documentation: Link, section Handling Local and Remote Notifications
Related
I have a question,
I work on a Swift 3 project with Xcode.
My goal is to send an alert sms, 20 secondes after receiving a local notification. when I'm in application, every things work well, but when my app is in background, it can do other tasks, like print some character, or play music, or send a text to a socket server, but it can't send the sms.
I think, when I receive an alert, if I could back to my application automatically, then I can send an alert sms, that's why I'm doing this stupide idea and looking for a way to know how I can wake up automatically my application and go back to the first View Controller Screen when I receive a Local Notification?
Maybe there is someone who knows a method to return to the iOS application automatically?
When your app is launched into the background—usually to handle some type of background event—the launch cycle changes slightly as given in the picture below. The main difference is that instead of your app being made active, it enters the background state to handle the event and may be suspended at some point after that. When launching into the background, the system still loads your app’s user interface files but it does not display the app’s window.
Reference - https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html
Bringing your app from background to foreground is not possible. And even if you are able to do so, App store will reject it.
Hope it helps!
Im developing an app that uses Ibm Mobile First Push Notification on iOS.
My question is how do i detect the app is open or navigate to, when user click on the notification banner at notification centre?
I know WL.Client.Push.onMessage does the trick. But this function is being fired too when the app is at foreground and a notification is received.
Is there a different function?
Thanks in advance.
In all cases (app closed, opened, etc...), there is a single function/callback that is called to process the incoming notification.
If I understand your scenario, you want to perform a different action with the notification, depending if the app is opened or not? Perhaps you can resolve this by setting boolean flags during runtime or assign "IDs" to the various app screens and check for the values of these and act upon them accordingly?
In my settings tabbar:
I have a feature specific switch which can be turned OFF or ON based on API response.
From website only admin is authorized to turn ON/OFF.
I can make /user API call everytime on settings tap to check the current settings for the user but there are couple of disadvantage like if user is already on setting then it will not update the UI and calling api everytime on settings tap doesn't sounds a perfect solution.
I think better solution is to send a silent push notification which i can use to make the API call to update the settings UI whenever needed.
But if user has disabled the push notification will I still receive silent push ? What is the recommended approach to handle such situations ?
Short answer, yes
The exciting new opportunity for app developers in iOS 8 is that Apple will now deliver “silent” pushes even if the user has opted out of notifications. Also, “silent push” is no longer just for Newsstand apps. Every app can take advantage of this ability to refresh content in the background, creating the most up-to-date, responsive experience possible, the moment the user opens the app.
Although...
Users still have the ability to switch off your app’s ability to process a “silent push” by means of the “Background App Refresh” control. Even though Apple Push Notification service (APNs) will deliver a push marked “content-available” to your phone, the OS will not wake up your app to receive it, effectively dropping it on the floor. However, opting out of “Background App Refresh” is a lesser-known capability not directly associated with Notifications. You don’t access this preference in your Notifications Settings--it’s located under General > Background App Refresh screen.
Keep this in mind when building your application.
Source:
https://www.urbanairship.com/blog/watch-list-ios-8-opt-in-changes
This matrix might help. At left hand side, it shows if "didReceiveRemoteNotification: " method will get called or not. Other two columns is related to setting app. Settings -> YourApp. If yourApp supports Notifications and background app refresh. Look into matrix to check when you app will receive silent push.
Other answers are good. But they are not official answers.
The official answer is in What's New in Notifications WWDC 2015 video:
Silent notifications are enabled by default. The user does not need to
approve your -- does not give permission to your app to use them, and
you can just start using them without asking the user for permission.
But silent notifications are the mechanism behind background app
refresh. At any point you know that the user can go in settings and
disable them. So you can't depend on them always being available. You
don't know if the user the turn them off, and you are not getting a
notification anymore. This also means that silent notifications are
delivered with the best effort. That means that when the notification
arrives on the user's device, the system is going to make some
choices.
For more see this image and this answer
One of our clients asked for this functionality: "Permanently display a message (or image) on the iPhone lockscreen".
Our initial ideas were:
Changing the device lockscreen image:
Couldn't find a solution for doing this. Couldn't find even a private API for it.
Playing an audio in background and display an album artwork. It has a few problems:
We cannot hide the volume and track buttons
Display a notification:
The notification will go away after the user skips the lockscreen
Any ideea how we can accomplish this request. Please note that the app is NOT intended to be distributed via AppStore. This is an internal app only. It should work on NON-Jailbreak devices through. The app will be enterprise distribuited.
Kind regards,
Artwork
If it's not intended for the app store, you could definitely use the artwork thing. Since you don't need to comply with the iOS guidelines, just warn your users that the lockscreen buttons won't work if you try using them. This link and this one should help.
Using the iOS 7 background fetch can help you manage messages display, as long as the app has already been opened once. To know if the app is opened, you can send ping to your server saving the current app state every X minutes. If the server doesn't receive an update, it will just guess that the app is not running, he'll send emails or push notifications to the user until he does so.
Issues:
If the user opens an app like Music or any other that can become a responder, it will override your message.
You can only display a message if the app is opened at least once.
Remote notifications
It could be a good option since a notification can stay on the lockscreen as long as the user or you doesn't clear the notification center (you have to set it). And you can remotely display any message without the app being launched.
Issues:
You have no way of knowing if he cleared the notification. An idea would be to send them an email if notifications have been disabled.
Users can just disable notifications.
Lockscreen image
You won't be able to change the device lockscreen image without a jailbroken device.
I'd go with the first one, if it's a client requirement it seems like a reliable one. It all depends on how much control they have on the devices.
I am writing an application that utilizes Apple's Push Notification Service. Some of the push notifications are based on the users location and should only be delivered if the user is a certain distance from an object. I don't want to continually update the user's position to my server and do the check that way, first, because of security reasons and second, to cut down on the network usage. Is there a way, when the push notification is received by the device, to do a check before the user is notified, and if it doesn't meet the criteria, discard the notification? Thanks for the help!
Nope, sadly you can't execute any code on the client side without the user clicking on the notification when the app is not launched. You'll have to do your check server-side to decide wether or not sending a push.
Push notifications that are received while you app is not running (the most typical case) is outside your control. Once they are sent, they will be received and shown to the user (assuming the user has granted permissions)
You do have control over push notifications if they are received while your app is running.
Maybe you could use local notifications (notifications that are generated and received from user's device) instead. You would have full control over when they are generated.
Bear in mind, background processing in apps is disallowed except for 4 things
Location tracking (You can subscribe to trigger code when user changes geolocation)
Alarms
Playing music
Voice over IP
Anything outside these cannot be executed in the background.
Starting with iOS7, your code can be run, I quote, "roughly the same time that the user sees the notification":
Multitasking Enhancements
Apps that use push notifications to notify the user that new content
is available can fetch the content in the background. To support this
mode, include the UIBackgroundModes key with the remote-notification
value in your app’s Info.plist file. You must also implement the
application:didReceiveRemoteNotification:fetchCompletionHandler:
method in your app delegate.
See more info here:
https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW10
and here:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW57
I haven't tried it yet but I wonder if you send a push notification payload which doesn't have the standard "alert", "badge" values in "apns" but in a custom value, it would still call your code but without displaying the push notification.