I want to copy a media file from Resource folder to camera roll in unit test.
Here my code :
-(NSString *)copyFileToCameraRool:(NSString *)fileName{
__block NSString* ret;
if (fileName != nil && [fileName length] > 0 ) {
UIImage *image = [UIImage imageNamed:fileName];
UIImageWriteToSavedPhotosAlbum(image, nil,nil, nil);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request add image to camera roll
XCTestExpectation *mXCTestExpectation = [self expectationWithDescription:@"XCTestExpectation"];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"error");
} else {
NSLog(@"url %@", assetURL);
}
[mXCTestExpectation fulfill];
ret = [assetURL absoluteString];
}];
}
[self waitForExpectationsWithTimeout:10 handler:NULL];
return ret;
}
When I'm running this code, an error occurred "[0] (null) @"NSLocalizedFailureReason" : @"The user has denied the application access to their media.".
Can anyone help me solve this problem ?
Thanks you.
Aucun commentaire:
Enregistrer un commentaire