ios - Couldn't create log directory -
when test application on ipad run i.e. call database , create folder , perform other task in console show me
2015-05-12 11:25:32.478 myapp[291:19680] [pllogging] couldn't create log directory: operation couldn’t completed. (cocoa error 513.).
when search, found answer nsfilemanager creating folder (cocoa error 513.)
but not abel remove this.
when shutdown , restart ipad line not show
question:
- why statement in console?
- the above statement can crash app in future?
- how remove cocoa error 513 ?
here code calling database
let filemanager = nsfilemanager() var sourcepath = nsbundle.mainbundle().resourcepath?.stringbyappendingpathcomponent("database.db"); let docspath = nssearchpathfordirectoriesindomains(nssearchpathdirectory.documentdirectory, nssearchpathdomainmask.userdomainmask, true)[0] as! string let databasestr = "database.db" let dbpath = docspath.stringbyappendingpathcomponent(databasestr) println(dbpath) if(filemanager .fileexistsatpath(dbpath) == false) { var error:nserror? filemanager.copyitematpath(sourcepath!, topath: dbpath, error: &error) println(error) }
and here functions create logs folder
func createlog(log:string) { autoreleasepool{ var formatter:nsdateformatter! = nsdateformatter() formatter.dateformat = "yyyy-mm-dd"; var datestring = formatter.stringfromdate(nsdate()).stringbyappendingstring("_templogs") formatter.dateformat = "yyyy-mm-dd hh:mm:ss"; var filemanager:nsfilemanager! = nsfilemanager.defaultmanager() var logfolder = nsbundle.mainbundle().resourcepath?.stringbyappendingpathcomponent("logs") let searchpath = nssearchpathfordirectoriesindomains(nssearchpathdirectory.documentdirectory, nssearchpathdomainmask.userdomainmask, true)[0] as! string let logstr = "logs" let logfolderpath = searchpath.stringbyappendingpathcomponent(logstr) if(filemanager.fileexistsatpath(logfolderpath) == false) { var error:nserror? filemanager.createdirectoryatpath(logfolderpath, withintermediatedirectories: true, attributes: nil, error: &error) } var logpath = logfolderpath.stringbyappendingpathcomponent(datestring).stringbyappendingpathextension("txt") var writestring = (formatter.stringfromdate(nsdate()).stringbyappendingstring(" ").stringbyappendingstring(log).stringbyappendingstring("\n")); var data = writestring.datausingencoding(nsutf8stringencoding) if(!filemanager.fileexistsatpath(logpath!)) { filemanager.createfileatpath(logpath!, contents: data, attributes: nil) } else { var output = nsfilehandle(forwritingatpath: logpath!); output?.seektoendoffile(); output?.writedata(data!); output?.closefile() output = nil } formatter = nil filemanager = nil } }
the 513 permission issue (nsfilewritenopermissionerror).
try println logfolderpath , double check if correct (or post here result).
d.
Comments
Post a Comment