Hi,
-(NSString *)restorePhoto:(NSString *)param param1:(NSString *)param1 param2:(NSString *)param2{
__block BOOL bResult = NO;
__block NSString *sFilePath = @"";
NSString *sAppDocPath = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] path];
sAppDocPath = [sAppDocPath stringByAppendingPathComponent: @"cn1storage"];
NSString *sTmpFilePath = [sAppDocPath stringByAppendingPathComponent: param];
NSData *data = [[NSFileManager defaultManager] contentsAtPath: sTmpFilePath];
__block NSConditionLock * albumReadLock = [[[NSConditionLock alloc] initWithCondition:WDASSETURL_PENDINGREADS] retain];
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[assetsLibrary saveImageData: data
toAlbum: param2
metadata: nil
completion: ^(NSURL *assetURL, NSError *error) {
if (error) {
bResult = NO;
} else {
bResult = YES;
//sFilePath = [NSString stringWithString:[assetURL absoluteString]];
//sFilePath = [[assetURL absoluteString] copy];
sFilePath = [[NSString alloc] initWithString:[assetURL absoluteString]];
}
[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
failure: ^(NSError *error) {
NSLog(@"[restorePhoto] There is an error: %@", error);
[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
];
/*
[assetsLibrary writeImageDataToSavedPhotosAlbum:data metadata:nil
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
bResult = NO;
} else {
bResult = YES;
}
[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
];
*/
});
[albumReadLock lockWhenCondition:WDASSETURL_ALLFINISHED];
[albumReadLock unlock];
[albumReadLock release];
[assetsLibrary release];
//[sFilePath autorelease];
NSLog(sFilePath);
return sFilePath;
}
It is the native function we called then the string return. We can sure the "sFilePath" value is exist before return. Then it goes cn1 library code till the error as previous post.
For your reference, the three strings params
1. param : tmp{datetime}_{filename e.g. IMG_123.JPG}
2. param1 : {filename}3. param2 : "Camera Roll"
Please help to find out the solution. I would appreciated if the problem could be solved in a few days.
Thanks and Regards,