objective c - Error when calling initWithFileURL -


i inherited following code:

- (id)initwithfileurl:(nsurl *)aurl {     if((self = [super initwithfileurl:aurl]) != nil) { 

this init method in class inherits uimanageddocument

when hits "if" line, i'm getting:

* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[nsurl initfileurlwithpath:]: nil string parameter'

so far, i've been unable figure out why. i've tested code in legacy project took from, works fine there. method getting called aurl populated (aurl not nil, seems ok) in both projects. wrong new project i've copied legacy code into, causing throw error? thanks.

edit added:

inserting nslog before "if" line outputs following value aurl

file:///var/mobile/applications/427babd3-9d9d-41b7-8b99-1586e93ffadd/documents/3fe3861a-ca4b-4859-b14b-5cc4a1c6e7b4.khp 

edit added, here code higher stack trace:

- (id)initwithfileurl:(nsurl *)aurl withformtype:(khformtype)aformtype {     if((self = [self initwithfileurl:aurl]) != nil) {         self.formtype = aformtype;     }     return self; } ...   nsurl *uniquefileurl = [[self class] uniquefilenameindirectory:documenturl withfileextension:document_ext];  //    khdocument *adocument = [[khdocument alloc] initwithfileurl:uniquefileurl withformtype:inputpaceform];     nslog(@"%d", [khprofileinfocontroller getformtype:@"inputpaceform"]);     khdocument *adocument = [[khdocument alloc] initwithfileurl:uniquefileurl withformtype:[khprofileinfocontroller getformtype:@"inputpaceform"]]; ...  + (nsurl *)uniquefilenameindirectory:(nsurl *)dirurl withfileextension:(nsstring *)fileextension {     nsfilemanager *filemanager = [nsfilemanager defaultmanager];     nsarray *existingfiles = [filemanager contentsofdirectoryatpath:[dirurl path] error:nil];     nsstring *uniquefilename;      {         cfuuidref newuniqueid = cfuuidcreate(kcfallocatordefault);         cfstringref newuniqueidstring = cfuuidcreatestring(kcfallocatordefault, newuniqueid);          uniquefilename = [[[dirurl path] stringbyappendingpathcomponent:(__bridge nsstring *)newuniqueidstring] stringbyappendingpathextension:fileextension];          cfrelease(newuniqueid);         cfrelease(newuniqueidstring);     } while ([existingfiles containsobject:uniquefilename]);      return [nsurl fileurlwithpath:uniquefilename]; } 

because aurl nil here, before calling super init , should check, if aurl nill or not. if(aurl) it.

a file url identifying location in application sandbox document data written. passing in nil or empty url results in throwing of nsinvalidargumentexception.

actully url providing in initwithfileurl not valid url, path. don't' forget valid url needs scheme; files, "file://". try building file url using [nsurl fileurlwithpath:]

url = [nsurl fileurlwithpath:newfilepath]; 

convert before calling initwithfileurl method.

reference uidocument

in case if aurl valid url, may checking self job

-(id)initwithfileurl:(nsurl *)url { self = [super initwithfileurl:url]; if(self) {  }  return self; } 

reference


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -