我正在通过读取XML文件http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime来确定事件是否存在。
它返回一个布尔结果,但我无法弄清楚如何使用objective-c访问它。这就是我到目前为止所做的:
NSError * error = nil;
NSString * responseString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime"] encoding:NSUTF8StringEncoding error:&error];
NSLog(responseString);
if (error) {
NSLog(@"%@", [error localizedDescription]);
}
if ([responseString isEqualToString:@"true"]) {
// Handle active content.
NSString *baseVideoUrl = @"http://streaming5.calvaryccm.com:1935/live/iPhone/playlist.m3u8";
NSLog(@" finalUrl is : %@",baseVideoUrl);
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:baseVideoUrl]];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
// Use the 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
} else {
// Inform user that the content is unavailable
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Live Service"
message: @"There is no service going on at this time"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
答案 0 :(得分:1)
首先,你的NSLog语句应该是:
NSLog(@"%@", responseString);
这将正确地注销响应字符串,然后你会得到这个值(我刚刚尝试过):
<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>
您的响应String不等于true,因为它是完全限定的XML String表示形式。您需要搜索字符串,您可以通过查找它是否包含文本“true”或“false”来执行此操作。
NSRange range = [responseString rangeOfString : @"true"];
if (range.location != NSNotFound) {
//String contained true
}
或者,您可以使用轻量级XML解决方案,例如GDataXMLNode