All Products
Search
Document Center

API permission extended configuration for iOS Mini Program

Last Updated: Feb 05, 2021

Some special APIs of Mini Program, such as Location, Camera, Album, etc., usually prompt the user for authorization, and the API can be executed after the user allows it.

The Mini Program container allows the following extensions for API calls:

  • Customize the prompt text, and the access party can control the text and display style.
  • Allow the access party to read and write permissions.
Note: This extended configuration is only available when the Mini Program permission control is enabled in the background.

Permission configuration

The Mini Program already has a default configuration key and corresponding API, see the following table for details:

Permission key API
Camera camera scan, chooseImage, chooseVideo
Album album saveImage, saveVideosToPhotosAlbum
Location location getLocation, getCurrentLocation
Microphone audioRecord startAudioRecord, stopAudioRecord, cancelAudioRecord

You can get the permission dictionary that the current Mini Program has requested:

authorized

Custom display

mPaaS supports the display of custom permission popups, you can set it through the interface in the image below.

custom-alert

The implementation steps are as follows:

  1. After the container is initialized, specify the delegate of the custom permission popup.

    1. - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    2. {
    3. ...
    4. // Mini Program API Permission Control
    5. [TAAuthorizeStorageManager shareInstance].authorizeAlertDelegate = self;
    6. ...
    7. }
  2. Implement custom popup method.

    1. #pragma mark Mini Program API Permission Control
    2. - (void)showAlertWithTitle:(NSString *)title appName:(NSString *)appName storageKey:(NSString *)storageKey callback:(void (^)(NSInteger index))callback
    3. {
    4. if ([title length] > 0) {
    5. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
    6. message:nil
    7. delegate:self
    8. cancelButtonTitle:@"Cancel"
    9. otherButtonTitles:@"OK", nil];
    10. self.callback = callback;
    11. [alert show];
    12. }
    13. }
    14. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    15. {
    16. if (self.callback) {
    17. if (buttonIndex == alertView.cancelButtonIndex) {
    18. // The user allows authorization, the callback parameter is 0
    19. self.callback(0);
    20. }else{
    21. // The user allows authorization, the callback parameter is 1
    22. self.callback(1);
    23. }
    24. }
    25. }