參考不少大神的著作,收集了一些iOS相關(guān)的問題疼鸟。
1.無法連接網(wǎng)絡(luò):
1.1: 需要在info中增加:SBUsesNetwork / Application uses Wi-Fi / App Transport Security Settings
1.2:如果在代碼中直接使用socket 去連接訪問網(wǎng)絡(luò)菇曲,那么1.1中的設(shè)置多半并不能保證socket成功忿墅;這時候就需要使用彈出無線數(shù)據(jù)選項的方式宣吱,讓用戶可以點擊選擇WLAN與蜂窩數(shù)據(jù),進(jìn)行授權(quán)來保證socket的成功城舞。
NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error == nil) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"%@",dict);
}
}];
[dataTask resume];