简体   繁体   English

ios-位置发生重大变化,并且没有互联网

[英]ios - significant location change, and no Internet

I am using Significant Location Changes, and this is working fine. 我正在使用“重要的位置更改”,并且工作正常。 I then call a web api, and pass location data to this. 然后,我调用一个Web API,并将位置数据传递给它。

However, when I am not connected to the Internet, it cannot send the message. 但是,当我未连接到Internet时,它无法发送消息。

How do I get around this? 我该如何解决? I have tried putting a sleep into a recursive send routine. 我尝试将睡眠放入递归发送例程中。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [NSThread sleepForTimeInterval:5.0f];
        [self postURL :post :function];
    });

This works fine with the app in the foreground. 这与前景中的应用程序配合良好。 It cannot send the message but will keep retrying, when the Internet is available it then sends the message, but when it is in the background it will call the postURL only once, the first time around the function. 它无法发送消息,但是会继续重试,当Internet可用时,它将发送消息,但是当它在后台时,它将仅在函数周围第一次调用postURL。

How can I get around this? 我该如何解决? Or is there a better way to get background notifications when the Internet is lost, and reconnected. 或者,当Internet丢失并重新连接时,是否有更好的方法来获取后台通知。

Found a solution to this, switched to using startUpdatingLocation rather than using startMonitoringSignificantLocationChanges . 找到了解决方案,改用startUpdatingLocation而不是startMonitoringSignificantLocationChanges

This now seems to work. 现在,这似乎可行。

I don't think startMonitoringSignificantLocationChanges is suitable for sending location data back to a server. 我认为startMonitoringSignificantLocationChanges不适合将位置数据发送回服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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