首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >布尔值的iPhone NSXML

布尔值的iPhone NSXML
EN

Stack Overflow用户
提问于 2011-06-24 03:11:55
回答 1查看 290关注 0票数 0

我正在通过读取XML文件http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime来确定事件是否为实时事件。

它返回一个布尔结果,但是我不知道如何使用objective-c来访问它。这就是我到目前为止所知道的:

代码语言:javascript
复制
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];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-24 05:19:04

首先,你的NSLog语句应该是:

代码语言:javascript
复制
NSLog(@"%@", responseString); 

这将正确地注销响应字符串,然后您将获得此值(我刚刚尝试过):

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>

响应字符串不等于true,因为它是完全限定的XML字符串表示形式。您需要搜索字符串,您可以通过查找它是否包含文本"true“或"false”来执行此操作。

代码语言:javascript
复制
NSRange range = [responseString rangeOfString : @"true"];

if (range.location != NSNotFound) {
    //String contained true
}

或者,也可以使用像GDataXMLNode这样的轻量级XML解决方案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6459396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档