startUpdatingLocation of LocationManager through silent push notification

后端 未结 4 1000
南笙
南笙 2021-02-04 22:39

I am creating app that needs to wake up in background at particular time .

I have tried :

  1. UILocalNotification : But i Don\'t want to use UILoca

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 23:28

    I have successfully implement this Using Silent Pushnotification & it Call startUpdatingLocation and I am able to get location data in delegate method :

    Using This Payload:

    {
        "aps": {
            "content-available": 1
        },
        "SilentPush": "4"
    }
    

    I have enabled location & remote notification for Background mode: enter image description here

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
    {
         __block UIBackgroundTaskIdentifier bgTask =0;
        UIApplication  *app = [UIApplication sharedApplication];
         bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [self.locationManager startUpdatingLocation];
    
     }];
    

    didUpdateLocations

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
            lastLoc=[locations lastObject];
            [logFile addLocObject:[NSString stringWithFormat:@"Loc: %@",lastLoc]];
    }
    

提交回复
热议问题