-2

I have already refereed the Stackoverflow Link :- How to check for microphone access at time of launch?

But I want to show alert in full screen for getting permission as shown in Shazam app.

App Site :- https://support.shazam.com/entries/26560426-Microphone-access-now-required-iOS7-

App Link :- https://itunes.apple.com/us/app/shazam/id284993459?mt=8

I want to show alert like this. Can anyone help me on this issue?

Code that i have tried so far :-

-(BOOL)requestforpermisssion
{

     __block BOOL result=NO;


    #ifndef __IPHONE_7_0
       typedef void (^PermissionBlock)(BOOL granted);
    #endif


        PermissionBlock permissionBlock = ^(BOOL granted)
        {
            if (granted)
            {
                [self setupRecording];
                result = YES;
            }
            else
            {
                // Warn no access to microphone
                result = NO;
            }
        };

        // iOS7+



            if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission:)])
            {
                [[AVAudioSession sharedInstance] performSelector:@selector(requestRecordPermission:)
                                                      withObject:permissionBlock];
            }



  return result;
}
Community
  • 1
  • 1
Leena
  • 2,678
  • 1
  • 30
  • 43

1 Answers1

1

In Shazam app, the first screen is simply a UIView with some text and buttons.

enter image description here

In the buttons(Don't Allow and OK), they are calling the block with value YES and NO.

If the user click Don't Allow button, a system generated alert will appear.

enter image description here

You can change the description of system generated alert by adding the string value in attribute Privacy - Microphone Usage Description. Add this attribute in your Info.plist file.

In your Permission block

PermissionBlock permissionBlock = ^(BOOL granted)
        {
            if (granted)
            {
                [self setupRecording];
                result = YES;
            }
            else
            {
                // Warn no access to microphone
                result = NO;
            }
        };
Himanshu Joshi
  • 3,391
  • 1
  • 19
  • 32
  • 1
    i agree with you morpheus but i want to customise system generated alert like shaman application. you will find link of app in above post. i request you to please check app and please give your feedback on it. – Anjan May 01 '14 at 07:59
  • @Leena You can customize the message by using `NSMicrophoneUsageDescription`. – Himanshu Joshi May 02 '14 at 09:30
  • In Info.plist file add the attribute `Privacy - Microphone Usage Description` as string with custom message as a value. – Himanshu Joshi May 02 '14 at 09:34
  • i agree with you we can change message but i wan to display first alert like shaman thats my main issue. i request you to please don't downnvote because my friend post question on behalf of me. my ask question feature is blocked. – Anjan May 02 '14 at 09:42
  • morpheus i wan to show that first screen with 2 buttons. i want to show that custom alert view. – Anjan May 02 '14 at 10:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/51878/discussion-between-morpheus-and-anjan) – Himanshu Joshi May 02 '14 at 11:04