LoginSignup
6
6

More than 5 years have passed since last update.

iOS8からカメラとかフォトライブラリ取得で失敗するようになったら。

Posted at

それは、
プライバシー設定とかのアクセス権が設定されていない可能性があります。
(自分はそうでした、iOS6から入ってたけど億劫しちゃダメだね・・・

もしも、アクセス権の設定の場合、
こんな感じのコードで、使えるようになるかと思います。

Objective-C
ALAuthorizationStatus stat = [ALAssetsLibrary authorizationStatus];
switch (stat)
{
   //  利用可能
   case ALAuthorizationStatusAuthorized:       //  アクセスが許可
   case ALAuthorizationStatusNotDetermined:    //  写真へのアクセスを許可するか未選択
   {
      // イメージピッカー起動
      [self setImagePicker];
      break;
   }
   //  利用制限
   case ALAuthorizationStatusRestricted:
   {
      //  設定>一般>機能制限 から利用が制限
      UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SS_ERROR_TITLE", @"Title")
                                               message:NSLocalizedString(@"SS_ERROR_MESSAGE_RESTRICTED", @"Message")
                                                      delegate:nil
                                             cancelButtonTitle:@"OK"
                                             otherButtonTitles:nil] autorelease];
      [alert show];
      break;
   }
   case ALAuthorizationStatusDenied:
   {
      //  設定>プライバシー>写真 から利用が制限
      UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SS_ERROR_TITLE", @"Title")
                                                       message:NSLocalizedString(@"SS_ERROR_MESSAGE_DENIED", @"Message")
                                                      delegate:nil
                                             cancelButtonTitle:@"OK"
                                             otherButtonTitles:nil] autorelease];
      [alert show];
      break;
   }

   default:
   break;
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6