[英]UIImagePickerController working on iOS device but not on iOS simulator?
我一直在物理iOS設備上運行我的應用程序一段時間沒有任何問題。 但是現在UIImagePickerController視圖不會出現在模擬器上。 我已經使用此處的方法將照片保存到模擬器中,並確認它們確實存在於圖像庫中的模擬器上。 Xcode中沒有彈出錯誤。 我嘗試過使用不同的源類型,但無濟於事。 知道我可能做錯了什么嗎? 非常感謝!
碼
UIImagePickerControllerSourceType sourceType;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
//Display photo library.
[self startImagePickerControllerFromViewController: self
usingDelegate: self
withSourceType: sourceType];
...
- (BOOL)startImagePickerControllerFromViewController:(UIViewController*) controller
usingDelegate:(id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate
withSourceType:(UIImagePickerControllerSourceType) sourceType
{
//Insure camera, controller, and delegate exist.
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
//Create the ImagePicker.
UIImagePickerController *imagePickerUI = [[UIImagePickerController alloc] init];
imagePickerUI.sourceType = sourceType;
//Only allow still images.
imagePickerUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
//Turn off editing.
imagePickerUI.allowsEditing = NO;
//Set the delegate.
imagePickerUI.delegate = delegate;
//Present the picker view.
[controller presentViewController:imagePickerUI animated:YES completion:nil];
return YES;
}
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
上述條件確保模擬器無法運行它,因為模擬器沒有攝像頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.