How to check notification data in url? - ios

I am new to iOS development. I want my app to periodically check a URL for data, and show a notification if data is available. I cannot use Google Cloud Messaging or Firebase Cloud Messaging as I am porting an Android app which doesn't use cloud messaging services.
Is there any way to implement this in swift?

Depends what you have in mind for "periodically".
You could set up Background fetch. In that situation, iOS will wake up your app to let it download things.
You can then use the local notifications whenever you detect new data.
The issue here is that you have no control over how often your app gets called. You can provide a hint, but iOS can decide not to wake your app for a while if it thinks it's appropriate. Don't count on being called more often than once an hour.
Another option is to have the app woken up by sending it a silent notification whenever there's something new (or at regular intervals).
The best option would still be to send notifications (silent or not) whenever there's actually something to send.

Related

Can you listen to Firestore updates when iOS app is in the background?

I'm very new to Firestore and trying to understand how the real-time updates work. I'm using something like this now to get the updates from Firestore:
db
.collection(Collections.session)
.whereField("participants", arrayContains:userID)
.addSnapshotListener { querySnapshot, error in
I noticed that the listener block is not getting fired when the app is in the background, but only when it's brought back to foreground.
Is there a way to get the update when the app is running in the background too? Maybe somehow send a push notification or something?
Any kind of help is highly appreciated.
Is there a way to get the update when the app is running in the background too?
Since backgrounded apps are eventually killed by the OS, you don't have a way to run a listener reliably when the app is not actively being used by the user.
You are correct in that the only way to (reliably) notify your app of some change in your backend is to send a push notification.
A very common approach is to use Cloud Functions to write a Firestore trigger that gets invoked when a document of interest is created, updated, or deleted. You can use this to write backend code that uses Firebase Cloud Messaging and the Firebase Admin SDK to send a notification to your app with a payload that tells it to respond to that change.
Push notification is not a reliable way to do this unfortunately. that backgrounded apps may be killed by the OS, if needed, but not always. The source of termination can be the OS or the user. If the user terminates your app, there is no way to receive a push notification.

Server sends data while iOS app is terminated

I have an application which has communication with a remote server. The server should push data into it using remote notification silently, and I need to get and store these data into a CoreData database. The user won't be aware of the whole process.
I can successfully get notified when the app receives a remote notification, while it is either in the foreground or background mode. However, I need to get data while the app is terminated as well.
I searched for the possible solutions. For example, this SO question was good if I don't tend to use silent notification. I also saw the PushKit capability, but I am not sure about the Apple Review result.
What is the possible solution?
If I want to use VoIP and PushKit to get notified when the app is terminated, would Apple reject my application?
If you’re not creating a VoIP app and you want your app to be in the App Store then the correct answer is: it is not possible. The only thing that can be done is adjusting your requirements in some way.
For instance you can send some notifications that will be visible for user in the Notification Center and wait until the user taps the notification or starts the app the usual way. Then the app will be able to do all the operations you need.
The delivery of push notifications is not guaranteed, so you should not rely on them to synchronise data.
For example, if multiple push notifications are sent while the device is offline, only the last notification is delivered when the device comes back online; the earlier notifications are lost.
When your app launches one of the first things it should do is check with your server for new data.

Firebase: Listen ChildEventListener even if app exits

I'm working on an iOS application, and want to achieve behavior like push notifications using firebase real time DB.
In case my app is listening to some firebase node and i'll send local push notification to the user in case that node is updated.
The issue is, if the app is not running i.e. user has killed it, will my app continue listening to that particular node?
I guess, in Android we've support like this, as explained in this link (Link).
Can we achieve the same behavior in iOS. If no, what can be the alternative?
Thanks
Update:
1- There's nothing like triggering push notifications locally in iOS app. I wanted to achieve remote notification's behavior and that can't be done.
2- As far as listening to some event is concerned, it can't be done when app is not in foreground or background.
You can’t do anything if an iOS app is killed/not present in memory.
However, you can do some tasks if app is in background, and is present in memory.
You can use background fetch request in this case.
In Android, there are Services which run even when the app is killed. But on iOS, there is no such thing like this.
You can add Firebase observers in your root view controller, and implement background fetch request to continue observing data when app is in background.
When you app is killed, the listeners are disconnected.
The typical way to send messages to your app in this state is by using a push notification, which in Firebase maps to Firebase Cloud Messaging.
This is why you'll often see the Firebase Database and Firebase Cloud Messaging (FCM) used hand-in-hand: the database is used for messaging while the user has the app open, and FCM is used to send messages when the app is not active.

Should I use Apple Push Notification or simply pull data in background for simple app?

I have an app that fetches data from server via json/http (actually, it synconizes data with Core Data). User needs to be notified when new data is available in 5-10 minutes. I am planning to have about 10 users (that as an internal enterprise app), so I can simply fetch data in background using NSURLSession.
But iOS may kill my app in case of low memory (or even user may kill it!), and no notifications would be delivered! So, I believe APN may be used. But this solution looks very complex for such a simple task and small number of users.
Ideally, I should have some service/daemon or (like IntentService on android), but I can't have it on iOS, so there are only 2 ways: APN or background app (which may be killed). What is the right way here?
Even if your app killed, your app can be opened in background and fetch data. This feature is called as background app refresh. After updating data, you can show user a local notification, which makes it easy by not using APNS. However, if you want to use APNS, you can use Amazon SNS to send push notifications. If i am not remembering wrong, it gives first million push notifications as free for every month. It is very easy to implement, though.

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.

Resources