OGeek|极客世界-中国程序员成长平台

标题: ios - 在后台将位置发送到服务器 - ios 7 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:22
标题: ios - 在后台将位置发送到服务器 - ios 7

当应用程序收到静默推送时,我尝试在后台发送用户位置。

我的代码:

application:didReceiveRemoteNotification:fetchCompletionHandler:

看起来像:

UIBackgroundTaskIdentifier bgTask = 0;
bgTask = [[UIApplication sharedApplication]  beginBackgroundTaskWithExpirationHandler:^{
          bgTask = UIBackgroundTaskInvalid;
    }];
[_cllManager startUpdatingLocation];
[[UIApplication sharedApplication] endBackgroundTask:bgTask];

locationManager:didUpdateLocations:

看起来像:

UIBackgroundTaskIdentifier bgTask = 0;
    bgTask = [[UIApplication sharedApplication]  beginBackgroundTaskWithExpirationHandler:^{
              bgTask = UIBackgroundTaskInvalid;
        }];
    // here I'm sending the request to server via AFNetworking
    [_cllManager stopUpdatingLocation];

    [[UIApplication sharedApplication] endBackgroundTask:bgTask];

我试图向自己发送一个无声的推送

有什么想法吗?



Best Answer-推荐答案


静默推送通知是不可靠的,如果为相同的服务/设备启用了正常推送通知,则不能保证始终在设备上传递。

我的建议是使用 1)苹果显着的位置变化特征。 2)使用区域监控

两者都可以在后台模式下完成。

关于ios - 在后台将位置发送到服务器 - ios 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139878/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4