NSXMLParserErrorMessage - 无法打开数据流

时间:2015-10-28 07:39:42

标签: ios swift watchkit nsxmlparser apple-watch

我遇到了一个奇怪的问题。我尝试从Apple Watch的非HTTPS Web服务器解析XML文件。 它在Xcode模拟器中与WatchKit 2.0和iOS 9.1配合使用,只要尝试在我的手表上构建它,它就不再工作了......

我还在所有Info.plist文件中设置了ATS:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

调试时发现以下错误:

[0](null)&#34; NSXMLParserErrorMessage&#34; :&#34;无法打开数据流&#34;

import Foundation
import WatchKit

class parkingXMLParser : NSObject, NSXMLParserDelegate{
    var parser = NSXMLParser()
    var elements = NSMutableDictionary()
    var element = NSString()
    let menuXMLURL = "http://ta-app.hslu.ch/parkplatz/HSLUHorw.xml"
    var parkingCounterFree =  NSMutableString()
    var parkingCounterTimestamp = NSMutableString()


    func beginParsing()
    {
        parser = NSXMLParser(contentsOfURL:(NSURL(string:menuXMLURL))!)!
        parser.delegate = self
    }

    func parse() -> Bool {
        return parser.parse()
    }

    func getParkingCounterFree() -> String {
        return parkingCounterFree as String;
    }

    func getParkingCounterFreeTimestamp() -> String {
        return parkingCounterTimestamp as String;
    }

    func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String])
    {
        element = elementName
        if (elementName as NSString).isEqualToString("ph")
        {
            elements = NSMutableDictionary()
            elements = [:]
        }
    }

    func parser(parser: NSXMLParser, foundCharacters string: String)
    {

        if element.isEqualToString("frei") {
            parkingCounterFree.appendString(string)
        }
        else if element.isEqualToString("zeitpunkt") {
            parkingCounterTimestamp.appendString(string)
        }

    }
    func parser(parser: NSXMLParser, parseErrorOccurred parseError: NSError) {
        NSLog("failure error: %@", parseError)
    }

}

0 个答案:

没有答案