iOS Push Notification concept - ios

I am fairly new to iOS development and wanted to know if my concept of how to set up and use push notifications on iOS.
So my general idea is that on each time the iOS app is opened (following Apple's guidelines) to register for push notifications and then handle the did register and failed to register methods. In the did register for push notifications I would post to my webserver the device id which I would store in the database with a last connected date.
The logic on the webserver side would be to update the existing record if the device id already exists to update the last connected date (there will be a cron job that purges device ids where they haven't been connected in the last 3 months say).
So once I have the device ids that are fairly current then I can iterate through these device ids when sending the push notifications, this way I won't be sending unnecessary pushes to devices that may not have the app installed any more.
Does this concept sound correct?

This should let you understand.

Related

Can I read others push notifications on iOS?

The main tread here, but is from 6 years ago (How can I read push notification from other apps?)
I'm making an app and I was thinking if is possible to read all of the push notification the device and get their data. (push notifications of others apps)
I know it is possible on Android. Is there any update for iOS?
TL;DR. No
APNs delivers remote notifications based on a token, generated by an app. The token at each moment of time is unique to the app instance, installed at the specific device. Only the app instance associated with the token is delivered with corresponding remote notifications.

What is the best way to keep updated the info of an iOS App?

Since push notifications may not be delivered sometimes (you can lose a few of them), you can not run code after the iPhone is turned on to check if there is new information available from the server, and you can not run code if your iOS App is closed... What can you do if you want to be as more accurate as possible in for example a Chat App in iOS?
I mean, inform the user as faster as possible that he has new info available. Comparisons: WhatsApp is updated without any delay.
You can do background fetch if your App is in background. But if the App is closed and you miss a push, it's not going to be up to date until the next push arrives or user opens the App. The same with silent notifications. If the app is terminated by the user, you are not going to receive it. Is there any way to solve it? It must be because other Apps do it... If there is any "private and secret" API that they are using (I read about this answer when no one know how to do that)... Is there any way to apply to use it?
UPDATE:
I'm using push notifications. The goal is to fix when a push doesn't arrive. Example: User A send chat message to user B. User B doesn't have the App open. The system lose the push. User B is not going to receive the message until he open the App.
Push notifications seems to be your only way even if you do loose a few of them, which I don't know how you would since they are pushed to apples secure server... but what do I know. As long as the user turns on the push notifications you should be fine. They may be delayed due to apples way of handling them. Honestly push seems to be the future, having your app constantly every minute or two check for new messages is a huge battery water in conjunction with normal texting apps. Your app should provide the best live data but since apple restricts to push notifications when the app is off or not running just stick to push notifications and only push major events to the user. I believe you can set up a job scheduler using quartz or schedulator to setup your server to push notifications to your app.

Fetching data from server & adding notifications

I am working on an app which fetches student info from a server, like absences and events and grades. I have no access to the server, I only have the API.
I am asked to implement push notifications in the app, such that if a teacher marks a student absent, that student get a notification about that. I searched and found several approaches:
1- Background fetch: I tried using background fetch to check if the student logged in to the app was marked absent today, if yes, show a local notification. It worked when I simulated w background fetch, but never worked on the physical device.
2- I searched for using Apple Push Notification Service, and they all wanted me to build a server, and I dont know how to start. Can I build a server which pushes notifications to devices in a way facebook does it? That is, one user triggers a notification at another user, in other words: I dont want to use broadcast notifications.
3- Using third party, like backendless, firebase or any alternatives. Would that be a useful approach?
With Backendless your app (on the student side) can register itself to receive push notifications. This is done with an API call that registers the device on the servers provided by Backendless. Then you would build an additional application (could be a browser web app or a mobile app) for the teachers. The system allows to send targeted notifications, so when a student is marked as absent, you could use the API to deliver a push notification specifically to the student's device. Would be happy to discuss in detail, you can post your question to the Backendless support forum.
For my app I have designed Push service using Java APNS library.
Or You could use Microsoft Azure Mobile services to push a notifications to devices.

Adding notification to app that makes pdfs

I have an app that creates pdf's for the user. When this app creates a new pdf (say on the users i-pad) I want the iwatch to display a notification saying a new pdf has been created.
Does this require a server, it was my understanding apple could provide this service.
Any help or tips would be appreciated!
First to address the difference between local and push notifications. Local Notifications would be used on the specific device the user is on at the time, and is normally scheduled for a specific time such as the reminder app notifying you at a scheduled time. Push notification are sent via a server to other devices.
Since you want to send to the other devices you will want to implement push notifications. In order to do this the user will need your app on all devices. Additionally you will need to have a login system so you know which devices belong to the same user. From there you will need a push notification service that can do targeted push notifications. There are many services out there and you will need to decide which one is right for your situation.
Push notifications are sent to the device by using the device token Apple provides after the user approves notifications for your app. Each app on each device has their own device token. So in addition to targeted notifications you will want a push service that allows you to setup channels such as parse.com, that way you can setup a channel specific to each user (email, username, or ...). Then when your user logs in on any device and approves getting push notifications, their channel will be set to (whatever option you choose) and you can trigger the push notification to the specific channel and will send the notification to any device.
There are other consideration but this is a good place to start.
Local notification is just that, local to that device. Remote notification is what you need. You will either need to create a server for this purpose or use one of the variety of third-party services (Urban Airship, Parse, etc) to provide that functionality.
Clarification point -- when you say:
I want their iphone, and every other device that they have to receive a notification that a new pdf has been created
it is assumed that you mean "every device of theirs that is running your app and has approved notifications from your app". If you're trying to piggy-back on some magic AppleID-related foo, that won't be possible.

Grouping ios push notification targets

It is possible to group,filter or exclude some of the push notifications receivers? Or every notification will be received by all receivers? Thx.
A push notification is sent to a single device only. Once it hits the device, if the user opts to open the app from the push, i.e. they tap the "View" button, it gets received by your UIApplicationDelegate instance (i.e. object conforming to the UIApplicationDelegate protocol) which is where you process it.
So in both of the places where you interact with the push notification system, there is just 1 entity you are dealing with. That is, you are pushing to a single device and when you receive it in your app it's a single instance that receives the data. So I'm not entirely sure what you mean when you want to group or filter some receivers.
If you mean that you want to only push to some of the devices that are registered then that is entirely up to your server. If you don't want to code this yourself then I suggest taking a look at something like http://urbanairship.com/ because they do a service where they handle all the server side of push notifications for you and give you facilities such as groups.
Further reading:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW10
You can do this now using our SDK (I'm CEO). It lets you target your Mobile App users by various criteria pulled from our Mobile App Analytics collector, so for example: to users of an App Version, iOS Version, Device Type... etc. www.AskingPoint.com

Resources