我有.plist文件,它位于两个不同的Web服务器上(冗余)。我已经完成了目标c,但我怎么能在swift中做到这一点?提前谢谢。
// Web Server 1或Web Server 2 - (BOOL)MyserverPL { NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@" http://www.myserver1.com"]]; [请求setHTTPMethod:@" HEAD"]; NSHTTPURLResponse *响应; [NSURLConnection sendSynchronousRequest:request returningResponse:& response error:NULL]; return([response statusCode] == 200)?是:否;
}
if([self MyserverPL] == YES)
{
data = [[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver1.com/playlists/my.plist"]];
// NSLog(@“Web Server 1 up and running");
}
else
{
// NSLog(@“Web Server 1 isn’t up and running so go to the Web Server 2");
data = [[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver2.com/playlists/my.plist"]];
}
}