IOS background service (like Android) turns on all the time

It's kind of a service in Andorid on IOS. What will run in the background from the start of the system? I am playing witch beacons and I would like to send a notification when the user is near the beacon. Is this possible on IOS?

Hello

+1


source to share


3 answers


You can do something in the background, but it doesn't work on Android. iOS will call a specific method to give you the option to update, then you have a limited time to do that.

You can still set a longer time for the application to go back to the background (approximately 10 minutes). Check out the beginBackgroundTaskWithExpirationHandler method

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html



Another solution is to use significant location changes. If the user is sharing their location with your app, you can get a callback when their position changes and use that time to update.

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

I know the dropbox app uses a location solution to upload your photos on the go from your camera roll to their services.

+1


source


Allowed only for certain applications. See https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW24 . For a complete explanation of background modes.



In a nutshell, apps can be suspended anytime in the background, exceptions are apps that ask for certain permissions to play continuously in the background (like voip apps or music apps), but Apple can deny your app store application if you ask for such permissions and your application does not actually provide any associated functionality.

+1


source


Yes. Check out Apple's Documentation for Location Monitoring .

From the docs

IOS always keeps track of the regions associated with your app, including when the app is down. If an area boundary is crossed when an application is not running, that application is restarted in the background to process the event. Likewise, if the application is suspended when an event occurs, it is woken up and given a short amount of time (about 10 seconds) to process the event. If necessary, an application can request additional background runtime by using the beginBackgroundTaskWithExpirationHandler: UIApplication class.

You probably need to add "Location Updates" as the allowed background for your application. I'm not sure if you need to enable "Use Bluetooth LE Accessories" or "Acts as Bluetooth LE Accessory", or maybe not.

Create a beacon scope for the UUID you want to monitor. See Apple docs again .

- (void)registerBeaconRegionWithUUID:(NSUUID *)proximityUUID andIdentifier:(NSString*)identifier {
    // Create the beacon region to be monitored.
    CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc]
       initWithProximityUUID:proximityUUID
                  identifier:identifier];
    // Register the beacon region with the location manager.
    [self.locManager startMonitoringForRegion:beaconRegion];
}

      

Manage Delegated Location Manager:

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region

      

You probably want to trigger a local notification when you handle an event. Apple docs on local notifications .

+1


source







All Articles