2017-05-16 11 views
0

私はカメラロールにアクセスするアプリを実装しようとしています。私もSettings.bundleそれを追加iOS:iPhone設定をPHPhotoLibrary権限にリンクする方法

-(void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:YES]; 
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 
    if (status != PHAuthorizationStatusAuthorized) { 
     NSString *accessDescription = [[NSBundle mainBundle] 
             objectForInfoDictionaryKey:@"NSPhotoLibraryUsageDescription"]; 
     UIAlertController * alertController = [UIAlertController alertControllerWithTitle:accessDescription 
                        message:@"To give permissions tap on 'Change Settings' button" 
                      preferredStyle:UIAlertControllerStyleAlert]; 
     UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" 
                   style:UIAlertActionStyleCancel 
                  handler:nil]; 
     [alertController addAction:cancelAction]; 
     UIAlertAction *settingsAction = [UIAlertAction 
             actionWithTitle:@"Change Settings" 
             style:UIAlertActionStyleDefault 
             handler:^(UIAlertAction * _Nonnull action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] 
               options:@{} 
            completionHandler:nil]; 

     }]; 
     [alertController addAction:settingsAction]; 
     [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController 
                        animated:YES 
                        completion:nil]; 

    } 
} 

:ここで私は権限をチェックしています方法です

enter image description here

しかし、私はにトグルスイッチをリンクすることができますどのようにそれを把握していませんパーミッション。どのようにトグルスイッチをカメラのロール権限にリンクすることができますか?

私は本当にあなたの助けに感謝します。

+0

を。 iOSはあなたが写真ライブラリにアクセスしたときにそれを行います。例えばhttp://stackoverflow.com/questions/13572220/ask-permission-to-access-camera-roll – Paulw11

+0

@ Paulw11、同じページhttp://stackoverflow.com/questions/13572220/ask-permission-to-access -camera-roll/38398067#38398067ユーザーに設定を送信しています – user2924482

+0

はい、設定が開きますが、自分のスイッチを置くことはできません。あなたが許可を求めたら、iOSはこれを行います。あなたがリンクしたコードでは、ユーザーが拒否した場合にユーザーに許可を要求することができます(iOSはユーザーに一度しか尋ねません。その後、設定したアクセス許可を使用します) – Paulw11

答えて

1

あなたはこのコードを試すことができます:あなた自身を要求しますが、この権限を管理しません

if (status == PHAuthorizationStatusNotDetermined) { 
     // Access has not been determined. 
     [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 
      if (status == PHAuthorizationStatusAuthorized) { 
       // do something 
      }else { 
       // Access has been denied. 
      } 
     }]; 
    } 
+0

これは素晴らしい動作です。しかし、ユーザーが「許可しない」から「許可する」に状態を変更したい場合。それは設定を介して行う必要があります。どのように設定を実装にリンクできますか? – user2924482

関連する問題