Apple Watch Kit 无法获取图像

Apple Watch Kit wouldn't fetch Image

A​​pple Watch Kit 无法从 URL

获取图像
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSLog(@"URL string for image %@",urlStr);
        NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
        });

提取在 Watch Simulator 中确实有效,但是当我 运行 它与手表一起使用时,我得到这些错误作为日志

2016-12-19 15:21:47.491560 Test app WatchKit App Extension[250:130169] dnssd_clientstub ConnectToServer: connect()-> No of tries: 1 2016-12-19 15:21:48.497360 Test app WatchKit App Extension[250:130169] dnssd_clientstub ConnectToServer: connect()-> No of tries: 2 2016-12-19 15:21:49.499671 Test app WatchKit App Extension[250:130169] dnssd_clientstub ConnectToServer: connect()-> No of tries: 3 2016-12-19 15:21:50.501699 Test app WatchKit App Extension[250:130169] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:7 Err:-1 Errno:1 Operation not permitted 2016-12-19 15:21:50.502103 Test app WatchKit App Extension[250:130169] [] nw_resolver_create_dns_service_on_queue DNSServiceCreateConnection failed: ServiceNotRunning(-65563)

您不能使用 NSDataWithContentsOfURL 下载图片。它在真实手表 os 设备中将不再有效。您可以使用 URLSession 或其他第三方库,例如 Kingfisher。