好吧,我有這個想通了。資產庫的問題在於它爲您提供了圖像的所有GEO數據。這意味着你的用戶使用你的應用程序的意思是,他們會得到一個提示,說你的應用程序正試圖訪問他們的位置。事實上,你所要做的就是讓他們從他們的相冊中選擇多張圖片。大多數用戶會被認爲是盜版問題。最好的方法是使用imagePickerController的蘋果api。我知道它可以讓你一次選擇一張照片,但如果你添加下面的代碼,它會讓你選擇多張照片。
我這樣做的方式是讓用戶不斷選擇他們想要的圖片,將這些文件保存在應用程序文檔目錄中,直到他們點擊完成按鈕。看到這裏我的示例代碼,並希望這將節省您要去的痛苦通過資產庫
-(IBAction)selectExitingPicture
{
//Specially for fing iPAD
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popoverController presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 300.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
//Done button on top
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
//NSLog(@"Inside navigationController ...");
if (!doneButton)
{
doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self action:@selector(saveImagesDone:)];
}
viewController.navigationItem.rightBarButtonItem = doneButton;
}
- (IBAction)saveImagesDone:(id)sender
{
//NSLog(@"saveImagesDone ...");
[popoverController dismissPopoverAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
//DONT DISMISS
//[picker dismissModalViewControllerAnimated:YES];
//[popoverController dismissPopoverAnimated:YES];
IMAGE_COUNTER = IMAGE_COUNTER + 1;
imageView.image = image;
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
// Give a name to the file
NSString* incrementedImgStr = [NSString stringWithFormat: @"UserCustomPotraitPic%d.jpg", IMAGE_COUNTER];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr];
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
//現在使用此代碼來獲取用戶選擇的照片。無論你想在你的代碼
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSString* dataFile = [documentsPath stringByAppendingPathComponent:@"UserCustomPotraitPic1.jpg"];
NSData *potraitImgData = [NSData dataWithContentsOfFile:dataFile];
backgroundImagePotrait = [UIImage imageWithData:potraitImgData];
將其轉換爲ARC並不困難.. – 2012-03-03 04:44:19