NSURLSession 使用 Objective-C 在 Watch OS2 上将数据返回为 Null [英] NSURLSession returns data as Null on Watch OS2 using Objective-C

查看:21
本文介绍了NSURLSession 使用 Objective-C 在 Watch OS2 上将数据返回为 Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在 iPhone(模拟器和设备)上完美运行,但在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆