NSURLSession returns data as Null on Watch OS2 using Objective-C

自作多情 提交于 2019-12-20 01:56:06

问题


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

回答1:


Sorry found the mistake. Had to add Allows Arbitrary Loads on the WatchKit extension. After adding i got the result.




回答2:


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

}


来源:https://stackoverflow.com/questions/33098581/nsurlsession-returns-data-as-null-on-watch-os2-using-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!