NSURLSession使用Objective-C在Watch OS2上将数据返回为Null

时间:2015-10-13 09:10:35

标签: objective-c watchkit apple-watch nsurlsession

这在iPhone(模拟器和设备)上完美运行,但在Watch OS2上,我得到空白数据。这可能是什么问题?

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];

2 个答案:

答案 0 :(得分:3)

抱歉发现了这个错误。不得不在WatchKit扩展上添加允许任意负载。添加后我得到了结果。

答案 1 :(得分:1)

[self.table setNumberOfRows:[arrurlimg1 count] withRowType:@“QuoteTableRow”];

for (NSInteger i = 0; i < self.table.numberOfRows; i++) {

    ICBQuoteTableRow* theRow = [self.table rowControllerAtIndex:i];

    NSURLSessionConfiguration  *config =[NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session =[NSURLSession sessionWithConfiguration:config];

    NSURLSessionTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data1, NSURLResponse * _Nullable response, NSError * _Nullable error)
                              {
                                  for (int i=0; i<arrurlimg1.count; i++)
                                  {

                                      UIImage *image =imgData1;
                                      [theRow.myFirstImage setImage:image];
                                      // [theRow.myGroup setBackgroundImage:image];
                                  }
                              }];
    [task resume];

}