我在Objective C中有個奇怪的問題。NSURL有時會給遠程服務器找不到初始嘗試的錯誤
我有這段代碼片段。問題是當我在Iphone或iPad上啓動應用程序4-5次時,我沒有找到遠程服務器,並且在殺死應用程序4-5次後都一切順利。服務器可用,並且可以從移動Safari瀏覽器進行瀏覽。
任何幫助將不勝感激。
NSURL *scriptUrl = [NSURL URLWithString:@"https://www.zzzzzz-zz.zzzzzz-zzzz.com/zzzzz/"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data)
{
//COMPAS is reachable
NSLog(@"Device is connected to the internet");
}
else
{
//COMPAS is not reachable
NSLog(@"Device is connected to the internet");
[self performSelectorOnMainThread:@selector(showHostAlert:) withObject:nil waitUntilDone:NO];
}
這樣我們就只能猜測發生了什麼。你確定它是https?永遠是你的服務器了。網址參數是否每次都正確? –