IOS判断camera是否可用,ActionSheet中button数量动态更改

示例如下:

UIActionSheet *playerIconSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
    
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])//判断camera是否可用。
    {
        [playerIconSheet addButtonWithTitle:@"Take Photo"];
    }
    [playerIconSheet addButtonWithTitle:@"Choose Photo"];
    
    [playerIconSheet showInView:self.view];
    [playerIconSheet release];

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == [actionSheet firstOtherButtonIndex] && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        //Take photo by camera
        [self getPicture:UIImagePickerControllerSourceTypeCamera];
    }
    if (buttonIndex == 1) {
        //Chose photo from PhotoLibary
        [self getPicture:UIImagePickerControllerSourceTypePhotoLibrary];
    }
}

原文地址:https://www.cnblogs.com/tx8899/p/2554542.html