【发布时间】:2014-05-13 11:53:46
【问题描述】:
即使应用程序在后台,我也在尝试更新用户在后台的位置,因此我触发了调用以下 php 脚本的位置更新:
-(void)locateUserAtLocation:(CLLocation*)location{
NSDictionary* dict=[self getCurrentAppAndUrlDictionary];
NSString* app=[dict objectForKey:@"app"];
float latitude=location.coordinate.latitude;
float longitude=location.coordinate.longitude;
NSString* language=[[NSLocale currentLocale] localeIdentifier];
NSString* nickName=[[NSUserDefaults standardUserDefaults] objectForKey:@"nickname"];
NSString* myUdid= [udid sharedUdid];
NSString *insertUrlString =[NSString stringWithFormat: @"http://www.miafoto.it/iPhone/inarrivo/taxi/insertUserNew.php?udid=%@&token=%@&nickname=%@&app=%@&language=%@&Latitude=%f&Longitude=%f&new=1",myUdid, token, nickName, app, language, latitude, longitude];
NSLog(@"url=%@", insertUrlString);
NSURLSessionDownloadTask *insertTask = [[self backgroundSession] downloadTaskWithURL: [NSURL URLWithString:insertUrlString]];
[insertTask resume];
}
但我得到错误: 后台下载的 URL 方案无效:(null)。有效的方案是 http 或 http 并且在前台或后台都没有发送 url。我在网上搜索我发现没有解决这个问题的命中。我还将问题提交给 Apple 支持。
【问题讨论】:
-
顺便说一句,虽然问题可能出在 URL 上,但顺便说一句,我原以为您想创建一个
POST请求(该请求是为提交数据以供 Web 处理时设计的服务)。此外,如果您在未来某个日期切换到 https,这将使 udid、令牌等比GET请求更安全。 -
是的,当然。我被错误信息欺骗了。现在它起作用了,但我发现了一个有趣的方面。似乎只有在连接到 wifi 时才会发送 url,而不是在蜂窝连接时发送,尽管我显然设置了:configuration.allowsCellularAccess = YES;在后台会话配置中。
标签: xcode ios7.1 nsurlsessiondownloadtask