苹果推送服务器位置,ios – 向应用程序发送静默推送通知,更新位置并在后台发送到服务器…

  • Post author:
  • Post category:其他


我想向后台的应用程序发送静默推送通知,然后获取当前用户位置并将其发送到Web服务.

我实现了推送通知方法以及这两个方法:

– (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

{

NSDate *fetchStart = [NSDate date];

[self sendLocationToServerWithCompletionHandler:^(UIBackgroundFetchResult result) {

completionHandler(result);

NSDate *fetchEnd = [NSDate date];

NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];

NSLog(@”Background Fetch Duration: %f seconds”,timeElapsed);

}];

}

– (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

{

}

我还创建了一个将位置发送到服务器的方法:

– (void)sendLocationToServerWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

{

NSDictionary *params = @{

@”UserId” : self.userId,@”Latitude” : self.latitude,@”Longitude” : self.longitude

}

ServerManager *manager = [ServerManager sharedManager];

[manager sendLocationToServerWithCompletion:^(BOOL success) {

if (success)

{

completionHandler(UIBackgroundFetchResultNewData);

}

else

{

completionHandler(UIBackgroundFetchResultFailed);

}

}];

}

我只是无法理解它们如何一起工作,Apple会批准它,它是否可能以及位置背景获取的位置.

提前致谢.