Save the picture to a sandbox or album:
1. Save to album:
-(void) Saveimagetoalbum: (UIButton *) sender{
Save a picture in an album
Uiimagewritetosavedphotosalbum (Self.image, Self, @selector (image:didFinishSavingWithError:contextInfo:), nil);
}
2. Save to Sandbox
-(void) Saveimagetosandbox: (UIButton *) sender{
Save a picture to a sandbox
Save File to Sandbox
Get the documents directory path in the sandbox
NSString *documents = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) firstObject ];
NSLog (@ "%@", documents);
NSString *documents = [Nshomedirectory () stringbyappendingpathcomponent:@ "/documents"];
NSLog (@ "%@", documents);
Stitching file Absolute Path
NSString *path = [documents StringByAppendingPathComponent:self.fileName];
Save
[Self.results Writetofile:path Atomically:yes];
}
This method is used regardless of whether the save succeeds or fails
-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) contextinfo{
if (Error! = nil) {
Uialertview *fail = [[Uialertview alloc]initwithtitle:@ ' Prompt ' message:@ ' save failed ' delegate:self cancelbuttontitle:@ ' OK ' Otherbuttontitles:nil, nil];
[Fail show];
NSLog (@ "%@", error);
}
else{
Uialertview *alert = [[Uialertview alloc]initwithtitle:nil message:@ "Save succeeded" delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil, nil];
[Alert show];
[Self.view Addsubview:alert];
}
}
Save a picture to a sandbox or album