Background Capablity on iOS - ios

What are the requirements and how would I go about implementing the Application Push Notification Service to trigger methods when the application is in the background, or when the phone is closed. Would this even be possible?
Thank you

No thats not possible.
When the app is in the foreground it will receive the push notification directly and can do whatever it wants to in response to that.
However when its not in the foreground the notification is displayed to the user (if they haven't disabled them) and/or displayed in the notification center (if they haven't disabled that). Your app will be brought to the foreground to execute if and only if the user selects the notification.
The application does not receive the notification directly if its not in the foreground.

Read the Apple Docs:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1

It boils down to lots of setup, and then implementing application:didReceiveRemoteNotification. You can read an in-depth example here. Part two goes into the actual application:didReceiveRemoteNotification implementation.

Related

Handle Push Notification when the App is off, or without opening the App at all - iOS

I'm building a Push Notification platform with Amazon SNS, using Amazon Cognito and other Amazon AWS tools, so far working flawlessly.
But my App is multi-language, so I'm trying to send just 1 single push message with a dictionary within the payload, this dictionary will contain an array with all the languages that I'm supporting.
So I just don't want to simply handle the message, what I'm intending is to do not show the push message at all before selecting the proper language that should appear to the user... With the App killed or not.
So my Q:
Is this seems possible?
What approach do you suggest to achieve this?
Thank you all very much.
No (when the user kills the app or when backgroundfetching is turned off, no notifications will reach your app).
Look into how to localize pushnotifications on apple's developer website. You can acieve exactly what you want by letting the system do the localization.
See the applicable keys in the push payload: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html
There are some limitations of APNS as follows:
didReceiveRemoteNotifications delegate execute only if the application is in either foreground or background.
If the application is terminated/suspended by either user or OS then notification will be displayed in notification centre but the respective delegate would not get called.
Set both Background fetch and Remote notifications enabled in Background modes from project setting.
Use application:didReceiveRemoteNotification:fetchCompletionHandler: delegate instead of didReceiveRemoteNotifications.
Hope this will help you.

Custom push notification screen

I'm developing an iOS video chat application. I would like to display a notification like the FaceTime application does when someone calls me.
Currently I use push notifications that show banners, with a message and a custom sound.
Instead I want my app to show a custom screen for an incoming event like someone calling me for example. Is that possible using apple public API's ?
Please, see the FaceTime notification screen below.
Ps.: Skype also uses a different notification screen.
Thanks a lot,
Daniel
I doubt it has anything to do with push notifications, in fact Skype you are mentioning was able to do it before push notifications were available.
Instead iOS gives you some extra features if you create an app with background mode "voip" (voice over ip). This will allow the app to wake up and brought to the foreground once traffic is detected on the network sockets, and applicationWillEnterForeground: is called. And from there you can use any view controller.
If you now think «hmm, my app doesn't offer voip, but I will pretend to do so to get superior notifications» — don't try it, apple will reject any app claims to be a voip app just to get endless background time.
No, push notification dialog is a system dialog which cannot be customized. However FaceTime is Apple's application and they can customize it the way they want, not open to third party developers.
However you can take advantage of iOS 8.0 addition "UIMutableUserNotificationCategory" to customize the actions in the notification:
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIMutableUserNotificationCategory_class/index.html
Example tutorial:
http://www.thinkandbuild.it/interactive-notifications-with-notification-actions/
I'm not sure how they did it, but Skype managed to get a customized notification when a User receives a call both while the device is locked and while in use.
http://blogs.skype.com/2014/09/22/skype-5-5-for-iphone-answer-skype-calls-in-an-instant/
EDIT: Looks like IOS8 added an Interactive Notifications API. This is likely your next question: How do I make interactive notifications in iOS 8 app?

How can I handle unread push notifications in iOS?

I have a iOS 5.1 application that registers to the APNS service to receive notifications. The register is successful and I receive the notifications correctly. The problem comes when I try to handle the notifications.
Once the application is running, the method didReceiveRemoteNotification in the AppDelegate is called correctly and so the notification is handled as intended. This, however, only happens when the application is running on the foreground.
However, when the application is running on the background or is simply stopped, that method is not called. I've read that you should add some lines to the method didFinishLaunchingWithOptions method to obtain the notification from the userInfo dictionary, and handle it. This works just fine, but ONLY when the application is opened by clicking on the notification at the Notification Center. This means that if you open the application by clicking on its badge, or simply by changing context if you were running it on the background, the app never realises that a notification came in. Additionally, if more than one notification was received, we can only handle one of them at once by clicking on the Notification Center, which is a pain :-)
Is there any way to read the pending notifications in the Notification Center? I know there is a way to flush them using the method cancelAllLocalNotifications but I haven't found a way to just read them. And I really need to handle all of them. I thought of implementing a communication protocol with the third-party notification server to retrieve the information again when the application comes to the foreground, but since the information is already in the operating system I would find it strange if it's impossible to access it somehow.
So, does anybody know a way to do it? Thanks in advance.
When a push notification arrives and the user clicks 'cancel', your app has no way to read that push notification again. You have to implement a separate functionality (most probably on server-side) to fetch a list of notifications sent to this device.
For example, if a chat functionality is provided in your app and you send chat messages via push notifications then you should also keep chat messages on the server. If a user clicks 'Cancel' on any push notification then that chat message will not be displayed on the iOS device. In that case when a app comes in foreground later, you make a call to the server and fetch all the past chat messages (sent via push notification).
Ok, So a possible solution would be to have another database table with the messages in with a 'read' flag and a messageID field? Which by default the read flag is NO, then when the app successfully reads this and displays, it updates the flag to YES?
And with only 256 bytes to play with, what sort of ID field length would be necessary?
Edit,
Executed this plan and its working successfully.

waking up ios applications without using ios notification

Is it possible to wake up a background application with a non ios notification center? e.g. if I were creating a calling or messaging application is it possible to wake the application via SMS.
Nope. If you want to call app outside the device, you should use APNS. On the device you can use local notification. Sending SMS to wake up app is kinda wrong. People don't like such solutions - imagine bunch of SMS every day for different apps. Sorry.
No.
If you have background code running, you can schedule a local notification to yourself. If the user clicks "Ok" then you will come to the foreground. See here for a description and sample code.
As far as I can tell, the only ways to launch an app without user input is via a custom URL handler or via an accessory. It doesn't sound like an accessory fits your use case. Sadly you can't open URLs from the background, so you can't use this to wake yourself.

Can an application receive a push notification while in the background without the user being informed?

I've read the Apple Push Notification documentation and it seems this isn't possible but was just wondering if there are workarounds etc.
If an application is in the background and a server sends a push notification, if there any way the application can receive an inidcation of that fact independently of the user tapping the action button?
No, that's not possible. The application does not get to know about an incoming push notification unless the user activates it with the action button.
No - but if the app is in the background, you can still use the network if you enable multitasking.
With Apple it's always pretty simple: if something is not possible, there won't be workarounds.

Resources