简体   繁体   中英

CLCircularRegion and wake up app

In application we have mechanism like native Reminder app in iOS with firing notifications when user enter or exit in some region.

But two devices behave differently (5 and 5s) in same time. All devices have enable notifications, and allow use locations.

Two devices have a some "travel" and in the route created 10 points. First device (5) when came to finish received only 6 notifications, (5s) don't receive any notification.

But my question is how I can know when my app is restart in background or continue working. Because, all log in app I redirect into a file, and after download container and analyze what happened in app in travel time.

I noticed app restart in same times when device is enter to region and my log marks fired in the file but notifications don't receive. This is happended when app try to get some information from web service in didFinishLaunchingWithOptions

And maybe this is problem. How to know distinguish restart app or continue working. Thx.

Are you checking UIApplicationLaunchOptionsLocationKey in didFinishLaunchingWithOptions similar to (sorry, Swift is what I have now):

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if launchOptions?[UIApplicationLaunchOptionsLocationKey] != nil {
        // app was launched in response to incoming location event
    }
}

Additionally, if you're not already doing this you may need to create notifications differently if app is in background:

    // Show an alert if application is active
    if UIApplication.sharedApplication().applicationState == .Active {
        if let message = notefromRegionIdentifier(region.identifier) {
            if let viewController = window?.rootViewController {                    
                showSimpleAlertWithTitle(nil, message: message, viewController: viewController)
            }
        }
    }
    else {
        // Otherwise present a local notification:
        let notification = UILocalNotification()
        notification.alertBody = notefromRegionIdentifier(region.identifier)
        notification.soundName = "Default";
        UIApplication.sharedApplication().presentLocalNotificationNow(notification)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM