how to check if rtmp or hls urls are exist or they'll give 404 error in swift

前端 未结 4 683
暖寄归人
暖寄归人 2020-12-18 11:24

I need to parse some data from rss and open related links from parsed rss in swift 2, for example i want to check this link is valid or not:

rtmp://185.23.1         


        
4条回答
  •  长情又很酷
    2020-12-18 11:53

    I found a solution here in Objective C, so I ported the code to Swift (though you'll need to test it):

    class testHandler: NSObject, NSURLConnectionDelegate{
    
        func testURL(urlPath: String){
            let url: NSURL = NSURL(string: urlPath)!
            let request = NSMutableURLRequest(URL: url)
            request.HTTPMethod = "HEAD"
            let connection = NSURLConnection(request: request, delegate: self)
        }
    
        func connection(connection: NSURLConnection,
            didReceiveResponse response: NSURLResponse){
                if response is NSHTTPURLResponse{
                    if (response as! NSHTTPURLResponse).statusCode==200{
                        //url exists
                    }
                }
        }
    
    }
    

提交回复
热议问题