本文介绍了NSURLSession使用Objective-C在Watch OS2上将数据返回为Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这在iPhone(Simlulator和设备)上完美运行,但在Watch OS2上却获得了空白数据.这可能是什么问题?
This works perfectly on iPhone (Simlulator and Device) but on Watch OS2 i get blank data. What might be the issue with this ?
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error)
{
theData = [[NSString alloc]initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];
NSLog(@"%@", theData);
}];
[task resume];
推荐答案
对不起,发现错误.必须在WatchKit扩展上添加允许任意加载".添加后,我得到了结果.
Sorry found the mistake. Had to add Allows Arbitrary Loads on the WatchKit extension. After adding i got the result.
这篇关于NSURLSession使用Objective-C在Watch OS2上将数据返回为Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!