background fetch and push

Hi,

I am trying to understand about the background work that can be done in iOS.


I am writing an app that is suppose to fetch data from an IoT accessory and sebd it to the cloud, so basically we are talking on 2 actions that I want to verify that can be done in the background.


From what I am reading in the forum, In order to guarantee the background action (in the forum its mainly fetching) I need to "wakeup" the app via push notification.

since I am planning to connect my IoT to the app, I am planning to send push notification using the BLE channel (that is alway active - as described here https://uynguyen.github.io/2018/07/23/Best-practice-How-to-deal-with-Bluetooth-Low-Energy-in-background/).
My questions are:

1. If the user does not allow my app to send push notifications, will this flow be possible?
2. Can I send silent notification using this method, as I understand it does not reuiqre the user to do something?

3. What about sending the data to the cloud in the background, can it be done?


Thanks!

Replies

since I am planning to connect my IoT to the app, I am planning to send push notification using the BLE channel

This statement suggests that you’ve misunderstood a key point. The Bluetooth LE background modes are not push notifications (search the article you referenced for push and you’ll find it’s not mentioned once). Rather, they are a completely different way of resuming your app in the background.

1. If the user does not allow my app to send push notifications, will this flow be possible?

Yes, because there are no push notifications here.

2. Can I send silent notification using this method, as I understand it does not reuiqre the user to do something?

I’m not sure I understand this question properly, but I suspect it has the same answer as the previous question (-:

What about sending the data to the cloud in the background, can it be done?

Yes. The basic rules for networking in the background are outlined in Technote 2277 Networking and Multitasking. Also, if the server speaks HTTP[S], you can upload while suspended using an

NSURLSession
background session.

The key factor here is the upload size and your required latency. If you’re uploading small amounts of data and you want low latency, you can prevent your application from suspending and use a standard session. In contrast, if you are uploading large amounts of data, or latency doesn’t matter, you can use a background session. Or you can use a hybrid approach, where you first try a standard session and then revert to a background session if you run out of time.

Apropos time, you’ll probably want to read my UIApplication Background Task Notes post.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for the input and let me clarify my questions.

Let me try and clarify my questions.


I am developing an application that will communicate with an IoT device, the app suppose to run once for a few hours.

That means that most of the time the app will be in the background.


Does an active BLE connection between the IoT device and the mobile phone will prevent the OS from terminate our app, will it let us push and send data while the app is in the background?


Regarding the "push notification" - As I understand the "State Preservation and Restoration" mechanism (as it described in the link above) can help me change the state of the application to active and even bring it to the foreground (with a user interaction).

If the IoT send notification to the mobile phone while the app is in the background or terminated by the OS, a local notification will be visible on the mobile phone and "restore" the app. In that scenario:

Does the restoration, even without bringing the app back to the forground, will allow me to fetch data from the IoT device and send it to the server. And the notification will be just to update the user that the is uploading data from the IoT to the server

Or

Do the user must bring the app to the forground inorder to send data from the IoT device to the server via the mobile phone?


Just to veify, you added a link to "Technote 2277" is not updated and it refer to iOS 4, is it the relevant for the current iOS version?


Thanks

is [TN2277] the relevant for the current iOS version?

Yes. Some minor details have changed since then, but the big picture stuff is unchanged.

Does the restoration, even without bringing the app back to the forground, will allow me to fetch data from the IoT device and send it to the server.

Using a BLE background mode you can resume (or relaunch) your app in the background. Once your app is running in the background, it can use the network according to the rules outlined in TN227 or, if the server speaks HTTP[S], using an

NSURLSession
background session.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"