Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从iOS向后台服务器发送位置坐标_Ios_Objective C_Background_Core Location_Uibackgroundtask - Fatal编程技术网

从iOS向后台服务器发送位置坐标

从iOS向后台服务器发送位置坐标,ios,objective-c,background,core-location,uibackgroundtask,Ios,Objective C,Background,Core Location,Uibackgroundtask,我正在开发一个应用程序,需要将用户位置发送到服务器。我必须每秒更新一次用户位置,并从后台将其发送到服务器 我可以在后台获取位置坐标,但如何在每秒钟将其发送到服务器? 请帮帮我 我发现这在一个应用程序中运行-这取决于您的服务器希望发送什么。但这里有一个使用AFNetworking 2.0的示例: - (void)sendLocation:(CLLocationCoordinate2D)coordinate { AFHTTPRequestOperationManager *manager =

我正在开发一个应用程序,需要将用户位置发送到服务器。我必须每秒更新一次用户位置,并从后台将其发送到服务器

我可以在后台获取位置坐标,但如何在每秒钟将其发送到服务器? 请帮帮我


我发现这在一个应用程序中运行-

这取决于您的服务器希望发送什么。但这里有一个使用AFNetworking 2.0的示例:

- (void)sendLocation:(CLLocationCoordinate2D)coordinate
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSDictionary *parameters = @{
                                 @"latitude": [NSNumber numberWithDouble:coordinate.latitude],
                                 @"longitude": [NSNumber numberWithDouble:coordinate.longitude]
                                 };

    [manager POST:@"http://example.com/yourendpoint"
       parameters:parameters
          success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"JSON: %@", responseObject);
    }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        NSLog(@"Error: %@", error);
    }];
}
每秒发送用户位置不是一个好主意。您更应该在更改时发送,或者在更长的时间间隔内发送


希望能有帮助。

谢谢reecon。我会试试这个,如果我们将位置发送到服务器的时间间隔更长,那么我们就不能像uber和OLA应用程序那样显示继续跟踪。如果您有任何解决方案,请让我知道。谢谢