简体   繁体   English

在iOS中重要位置更新时联系服务器

[英]Contact server on significant location update in iOS

I am using significant location update in my app. 我在我的应用程序中使用了重要的位置更新。 I have tested by writing the location updates to file. 我已经通过将位置更新写入文件进行了测试。 It is working perfectly fine. 运行正常。 But how do I send the location update to the server? 但是,如何将位置更新发送到服务器?

Right now I am doing it this way, in didUpdate function, I am calling a function: 现在,我正在这样做,在didUpdate函数中,我正在调用一个函数:

Login* login = [[Login alloc] init]; // Login is subclass of nsobject
[login sendLocUpdate:latLong];

In sendLocUpdate , I am using NSUrlConnection to send the location to server. sendLocUpdate ,我正在使用NSUrlConnection将位置发送到服务器。 This is not at all updating the server but it is executing the function that writes the location detail to file properly. 这根本不是更新服务器,而是正在执行将位置详细信息正确写入文件的功能。 Please help me out? 请帮帮我吗? Thank you! 谢谢!

You should use the Login object the way it will persist all the time while the networking in a process. 您应该以登录对象始终存在的方式使用该对象,同时在过程中进行联网。 The "login" in your function is been destroying after the function run to the end. 函数运行到最后后,函数中的“登录”被销毁。 One possible way is to create it as a singleton instance (shared instance) and it will live all the time the app live. 一种可能的方法是将其创建为单例实例(共享实例),并且它将在应用程序运行期间一直存在。

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

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