爲布爾方法我有這個Web服務:Objective-C的 - 從Web服務
<boolean xmlns="http://schemas.microsoft.com/2003/10/Serialization/">true</boolean>
而且我在這裏有這樣的方法:
-(void)deviceCheck:(NSString *)device Completetion:(void (^) (NSArray * result,NSError * error))completion{
NSString *deviceRequestString = [NSString stringWithFormat:@"%@?device=%@",webservice,device];
NSURL *JSONURL = [NSURL URLWithString:deviceRequestString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:JSONURL];
NSURLSessionDataTask * dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(data == nil){
completion(nil,error);
return;
}
NSError *myError;
NSArray *tableArray = [[NSArray alloc]initWithArray:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myError]];
completion(tableArray,myError);
}];
[dataTask resume];
}
,但是當我把這個:
[self deviceCheck:[[UIDevice currentDevice] name] Completetion:^(NSArray *result, NSError *error) {
if(result == nil){
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message" message:@"Device is not valid." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
[self presentViewController:alertController animated:YES completion:nil];
}else{
}
}];
結果爲零。
我在這裏做錯了什麼?我將如何調用這個布爾型的Web服務。
我做了的NSLog上的錯誤:
Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
修正了一個錯誤與此:https://github.com/meteor/meteor/issues/4560
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set."
做一些調試。在'dataTaskWithRequest'完成方法中,data''nil'?如果是這樣,錯誤是什麼? – rmaddy
數據是零,現在我有斷點問題,看來我的方法是不會被調用 –
這是錯誤我得到NSError \t NSError \t域:@「NSURLErrorDomain」 - 代碼:4294966294 –