Push notifications to wake background app - swift

I am trying to have my app execute functions in the background on a regular basis. As performFetchWithCompletionHandler is too unpredictable I read about APNs.
Can I use APNs to periodically send a silent push notification to the device that would make the app execute my data fetching and analyzing functions then displaying a notification to the user accordingly?
Is it possible to have the server send the "wakeup signal" only and have the app display the notification by itself because of this?
I might have misunderstood the APNs logic entirely.

Related

How to automatically send a scheduled notification everyday in Flutter

I have an app that needs to send a reminder notification everyday at a user specified time. For now, I have used flutter_local_notification and used the zoneSchedule method to send a notification locally for that particular day after fetching the time from firebase.
My question is how should I make it so that this notification is sent everyday? When should the scheduling happen.
The specified time can be changed by the user.
I'd like the notification to be sent even when there is no internet connection.
If the app is not in the foreground the app is suspended, so your code wont execute.
You can wake up the app via a push notification from an external source but this will not work if the app has no internet connection.
If you want to execute it without an internet connection, you have to register a background task.
See:
https://docs.flutter.dev/development/packages-and-plugins/background-processes
https://pub.dev/packages/workmanager

TVOS remote notification replacement

I am building a TVOS app for the new Apple TV that needs to get notifications from a server to update it's display. Remote notifications are not allowed with TVOS, and it actually displays an error when you try to register the app for remote notifications.
With this being said, are there any alternatives to what I need?
To clarify:
- The app stays running indefinitely, showing a display.
- When the user adds content to the display, I want to notify any apps that are logged in to the same user to update the display.
- I cannot use remote notifications.
Please let me know if this makes sense, and thank you in advance for your help!
What part of the registration errors out for you? Notification dialogs and banners may not really make sense on tvOS, but can you send a silent push notification? All you need to do to register for these is
[application registerForRemoteNotifications];
You do not need to display the request dialog to the user for permission for silent notifications (you do need to have the remote notifications entitlement though.)
According to Apple's documents here, they allow CloudKit. CloudKit subscriptions rely on silent push notifications that I would assume would work on tvOS (without them it would severely cripple CloudKit)
If that still does't work, then you could create your own long polling connection (essentially, you would be making your own custom push notifications). It would only be able to send messages to devices that have the app opened however.
I guess you can have the app poll a web server at a given interval to check if any updates have been made...

How to get local notifications when app enters the background

I am new to iphone. I am doing Project in that i have struck in the middle because of local notifications concept.In my applications i am sending the request to the server and getting response for every 20 sec by using timer concept but when the application enter the background
how can we get the response from the server for every 20 sec by using local notifications.If anybody knows this concept please help me...
When App on background mode , you receive loacl notification, and you click yes button then
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
this function is call and you get dictionary
NSLog(#"%#",[notif userInfo]);
and call the xml in this function.. and you can get resonance from your server very easily
Generally, your app doesn't get to execute in the background, and local notifications won't provide you the ability to execute in the background.
(There are exceptions to this, but they come with limitations. If you really need to ping a server every 20 sec because you're something like a VoIP app, you can declare that you're a VoIP app and set up a keep-alive handler for doing that ping. However, if you're submitting to the App Store, Apple will require that you're really implementing a VoIP-like app, and not just downloading new RSS feeds in the background or some such.)
What local notifications are for is getting the user's attention when your app isn't active. While your app is running, you can schedule a local notification to post a message to the user some time later (sort of like a calendar alarm). If you're using one of the supported background execution modes, you can use a local notification to get the user's attention right now. Either way, your app only gets activated if the user chooses to tap the notification.

any option to know if apple app get the push notification?

I build xcode app that get push notification, the main problem is that the push notification is very critical for me.
so I want to check if the push notification is delivered to the device with the app installed, I understand that if the iphone dosn't have internet connecction / 3G the push notification is not getting to the device.
how can I check if the device get the notification or not?
how can I check if the APNS successful to deliver the push notification?
I want to send sms if the push notification is not deliver to the device so I think about the idea to get the notification event when it's open by the push notification, and to send request to my server so i can know if the push notification is successful deliver or not. the main problem is that the user need to open the app every time he get the notification and in the night it's a problem. so this option is not good for me.
I check the feedback server push notification but i don't find any info that I can get if the push notification is delivered or not
any idea??
With iOS7 you have a new method called
application:didReceiveRemoteNotification:fetchCompletionHandler:
which you probably could use for your task. From Apple's Docs:
Implement this method if your app supports the remote-notification background mode.
...
When a push notification arrives, the system displays the notification to the user and
launches the app in the background (if needed) so that it can call this method. Use this
method to download any data related to the push notification. When your method is done,
call the block in the handler parameter.
Unlike the application:didReceiveRemoteNotification: method, which is called only when
your app is running, the system calls this method regardless of the state of your app.
The short answer, you can't, since APNS is one way. However, since an app can execute arbitrary code upon receipt of a notification, you can use this to say, send an http request to your own server when the notification is recieved.
There are any number of reason why push notifications might not get delivered to your user, or might not be delivered in a timely manner. Apple does not provide any mechanism for you to query the status of a push notification that you have sent.
If your app is currently running on the user's device and the user is accepting notifications for your app, you can implement the following method in your app delegate. It would be called whenever a push notification is received and in this method you could send a request back to your server to indicate the message was received. However this will only work while the user is running your app.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
In general though, it sounds like you'e relying on push notifications for something you shouldn't. From Apple's Local and Push Notification Programming Guide:
Important Because delivery is not guaranteed, you should not depend on
the remote-notifications facility for delivering critical data to an
application via the payload. And never include sensitive data in the
payload. You should use it only to notify the user that new data is
available.
There is no way to find out whether the notification was delivered to the device or no. APNS is a one way service. If there is no internet connection on the device then the APNS server will hold the last notification for some period of time which is no specified by Apple. If a new notification is sent to APNS for delivery then the old notification data is lost and replaced by the new data if its undelivered. If the notification is delivered then also the old notification data is deleted on the APNS server.
Please go through the following link : Apple Push Notification
Hope this helps you...........
If you are using JAVAPNS to send the APNS notification, you can use the below:
List<PushedNotification> notifications =
Push.combined("alert", badge, "default", "cert.p12", "certpassword", true, deviceToken);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
//Push is successful. Do your thing...
}
else {
//Push is not successful. Do your thing...
}
}

Handle APNS Remote Notifications while in Background

I have implemented all recommended methods in AppDelegate to get working Remote Notifications service.
I can accept them while running, while launching and while turned off.
But there is an issue, since I can't work with many received notifications while in background. I can work only with latest notification.
What is recommended manual to do that? How can I got all notifications received while in background? Is it only solvable via manual call to my service provider (sender of apns data)?
With all the projects I've worked on there hasn't been a way to locally store this information if the push notification is dismissed. In all those cases we used a small file on the server that the app would connect to and pull when it became active again. There was also some place in the app where the user could see all their notifications which, again, were stored on the server for quick retrieval.
With the way I understand push notifications to be setup, if the notification is dismissed the system discards it. It'll perform anything it's supposed to do (such as update the badge number and play the correct sound) but any additional information specific to that notification is lost.
Not sure if this helps, but if you just want to know how many notifications you have missed while you were in background. You can create a variable which contains notification number and store this in the app every time you handle notification. When you come out of background and receive a new notification you can subtract the new number with the stored number to find out the number of missed notifications. I don't think there is a way where iOS can give you complete data associated with all the notification device have received while the app was in background.
The best solution is to keep a list of sent notifications with all relevant data on your server, so the app can access that data when it launches. Sending multiple notifications with data that is not stored on the server can be risky, because the application only receives the notification when the user opens the app from that notification, so if they tap on one notification, the app will only every receive that one.
If you have them all in a list on your server, the app can simply go and pull that list down, and process it, making sure no data is lost.