UIStatusBarStyleBlackTranslucent is not available on this device

痞子三分冷 提交于 2019-12-05 10:13:27
Zubair

For iPad it is recommended that you should use popover to present the MediaBrowser (camera / photoLibrary):

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];

UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:ipc];
popOverController.delegate = self;

You can also set the content view for popover:

ipc.delegate = self; 
ipc.editing = NO;       
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];

[popOverController presentPopoverFromRect:btnGallery.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Try below code its works for me perfect

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:   (NSInteger)buttonIndex
{
if(buttonIndex==0)
    {
    [self takePhoto];

    }
else if(buttonIndex==1)
    {
    [self choosePhoto];
    }
}


-(void)takePhoto
{
UIDevice *device = [UIDevice currentDevice];

NSString *currDevice = [device model];

NSLog(@"device is %@",currDevice);

   if(![currDevice isEqualToString:@"iPhone Simulator"])
        {
       [[UIApplication sharedApplication]    setStatusBarOrientation:UIInterfaceOrientationPortrait];
    UIImagePickerController *imgPickerCon = [[UIImagePickerController alloc] init];
    imgPickerCon.sourceType = UIImagePickerControllerSourceTypeCamera;
    imgPickerCon.delegate = self;
    [self presentModalViewController:imgPickerCon animated:YES];
    [imgPickerCon release];
    imgPickerCon = nil;
    }
  else{
    UIAlertView *alrt=[[UIAlertView alloc] initWithTitle:@"Message" message:@"Camera Will Not Open in Simulator" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alrt show];
    [alrt release];
}
 }

 -(void)choosePhoto
 {

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
UIImagePickerController *imgPickerCon = [[UIImagePickerController alloc] init];     
imgPickerCon.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgPickerCon.delegate = self;
[self presentModalViewController:imgPickerCon animated:YES];        
[imgPickerCon release];
imgPickerCon = nil;
  }


  - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated:YES];
 }

   - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)myimage editingInfo:(NSDictionary *)editingInfo 
  {


[picker dismissModalViewControllerAnimated:YES];
image=myimage;

imgView.image=myimage;

  }

Try removing your status bar settings from the plist file all together and adding the following to your AppDelegate's applicationDidFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
}

UPDATE:

Try this

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex)
{
    case 0: 
    {

        imgController = [[UIImagePickerController alloc] init];
        imgController.allowsEditing = YES;
        imgController.sourceType =  UIImagePickerControllerSourceTypeCamera;   
        imgController.delegate=self;
        [self presentModalViewController:imgController animated:YES];

    } 
    case 1:
    {
        imgController = [[UIImagePickerController alloc] init];
        imgController.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
        imgController.delegate=self;
        [self presentModalViewController:imgController animated:YES];  
    }
}
} 

A little late but is the UIViewController whats calling presentModalViewController:animated: a child of a UIPopoverController? If so, thats whats causing this. Try calling it from the popovers parentViewController

Bryan Tung

Just as you pointed out with the post that you have read, the simple solution would be adding a row in the plist with the following key-value

UIStatusBarStyle~ipad | String | UIStatusBarStyleBlackOpaque

(3rd row in the picture here, sorry cause I can't post image yet now)

This is one of the solution if you don't want to do too much "dirty work" on the codes there, just leave it to the plist to get the job done.

But if you don't mind writing codes, the solution given by VSN will do the same as my suggestion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!