gpt4 book ai didi

iOS:使用设置切换 PHPhotoLibrary 权限

转载 作者:行者123 更新时间:2023-11-28 21:09:50 25 4
gpt4 key购买 nike

我正在检查相机胶卷的权限:

-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
}
}];
}
}

它工作正常,但问题是如果用户选择“不允许”并且它想切换到“允许”。

用户如何切换到相机胶卷的权限?

最佳答案

你可以要求你的用户打开权限,如果他们说“是的,我想打开这个权限”那么你可以直接使用 NSURL 将他们传送到你的应用程序的设置中的首选项,他们也可以返回到单击状态栏左侧的后退按钮可返回您的应用程序。

这是将用户传送到您应用的首选项的代码:

NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];

这是我在 iOS10 iPhone6s 中测试的完整代码:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Need Photo Permission"
message:@"Using this app need photo permission, do you want to turn on it?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
}];
[alert addAction:yesAction];
[alert addAction:noAction];
[self presentViewController:alert animated:YES completion:nil];
}
}];
}
}

关于iOS:使用设置切换 PHPhotoLibrary 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44030505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com