Saturday 15 February 2014

ios - Downloading Files from server Objective C or Swift -



ios - Downloading Files from server Objective C or Swift -

how can download sound files server user's phone used in app? when go website link, json code comes this

class="lang-json prettyprint-override">[{"name":"lets party","path":"http:\/\/domain.us\/\/\/audios\/\/lets party.wav"}, {"name":"let know","path":"http:\/\/domain.us\/\/\/audios\/\/let know.wav"}, {"name":"omg","path":"http:\/\/domain.us\/\/\/audios\/\/omg.wav"}]

i tried getting json , converting in swift, crashed app. when set blog json, works perfectly, no crash. how can in either swift or objective-c?

edit: error message now.

current code:

allow urlpath = "http://www.domain.us/" allow url = nsurl(string: urlpath) allow session = nsurlsession.sharedsession() allow task = session.datataskwithurl(url, completionhandler: {data, response, error -> void in if error != nil { println(error) } else { allow jsonresult = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers, error: nil) nsdictionary println(jsonresult) } }) task.resume() }

error message:

2014-11-12 20:07:23.652 json practice[6073:284290] cfnetwork sslhandshake failed (-9847) 2014-11-12 20:07:23.874 json practice[6073:284290] cfnetwork sslhandshake failed (-9847) 2014-11-12 20:07:24.054 json practice[6073:284290] cfnetwork sslhandshake failed (-9847) 2014-11-12 20:07:24.055 json practice[6073:284290] nsurlconnection/cfurlconnection http load failed (kcfstreamerrordomainssl, -9847) error domain=nsurlerrordomain code=-1200 "the operation couldn’t completed. (nsurlerrordomain error -1200.)" userinfo=0x7fc0ba656020 {nserrorfailingurlstringkey=https://www.domain.us/, nserrorfailingurlkey=https://www.makemeip.us/, _kcfstreamerrordomainkey=3, _kcfstreamerrorcodekey=-9847, nsunderlyingerror=0x7fc0ba52ebb0 "the operation couldn’t completed. (kcferrordomaincfnetwork error -1200.)"}

// // viewcontroller.swift // test2 // // created adm on 11/14/14. // copyright (c) 2014 dabus.tv. rights reserved. // import uikit import foundation import avfoundation class viewcontroller: uiviewcontroller { @iboutlet weak var strfiles: uitextview! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. if allow url = nsurl(string: "http://www.anyurl.com/") { if allow loadedstring = string(contentsofurl: url) { // file string sucessfully loaded // add together file path + / + filename + extension allow localurl = (nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] string) + "/" + "data" + ".db" // documents url string (local storage path) // check local file path url if allow checklocalurl = nsurl(fileurlwithpath: localurl) { allow savedfile = loadedstring.writetourl(checklocalurl, atomically: true, encoding: nsutf8stringencoding, error: nil) // write url savedfile true or false if savedfile { // whatever self.strfiles.text = "\(self.strfiles.text)path: \(checklocalurl)\n" self.strfiles.text = "\(self.strfiles.text)file sucessfully saved\n" } // lets create array string var arraylines = "" if allow myarrayparsed = loadedstring.jsonparsearray() { elem:anyobject in myarrayparsed { allow name = elem["name"] string allow path = elem["path"] string arraylines = "name: \(name), path: \(path)" self.strfiles.text = "\(self.strfiles.text)\(arraylines)\n" } } else { // not parse array } } else { // not check local url } } else { // not load string contents url } } else { // invalid url } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } } extension string { func jsonparsearray() -> [anyobject]? { if allow info = self.datausingencoding(nsutf8stringencoding) { if allow array = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions(0), error: nil) as? [anyobject] { homecoming array } } else { homecoming nil } homecoming [anyobject]() } }

ios objective-c json audio

No comments:

Post a Comment