All Products
Search
Document Center

Mobile Platform as a Service:Mini program permissions

Last Updated:May 14, 2024

Some special APIs of mini programs, such as location, camera, and photo album, usually prompt the user for authorization. These APIs can be executed only after the user allows it.

The mini program container allows the following extensions for API calls:

  1. Custom text prompts, the access party can control the text and display style.

  2. Allows the access party to read and write permissions configuration.

Note

This extended configuration is available only when mini program permission control is enabled in the background.

Permission configuration

The mini programs' default key and the corresponding API are shown in the following table:

Permission

key

API

camera

camera

scan, chooseImage, chooseVideo

photo album

album

saveImage, saveVideosToPhotosAlbum

location

location

getLocation, getCurrentLocation

microphone

audioRecord

startAudioRecord, stopAudioRecord, cancelAudioRecord

You can obtain a dictionary of permissions that the current mini program has requested:

image

Custom display

mPaaS supports to customize the dialog box of permissions.

The steps are as follows:

  1. After the container is initialized, specify the delegate in the custom permissions dialog box.

     - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
        ...
    
         // Manage mini program API permissions.
        [TAAuthorizeStorageManager shareInstance].authorizeAlertDelegate = self;
    
        ...
     }
  2. The method of implementing a custom permissions dialog box.

    #pragma mark mini program API permission control
     - (void)showAlertWithTitle:(NSString *)title appName:(NSString *)appName storageKey:(NSString *)storageKey callback:(void (^)(NSInteger index))callback
     {
         if ([title length] > 0) {
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                             message:nil
                                                            delegate:self
                                                   cancelButtonTitle:@"Cancel"
                                                   otherButtonTitles:@"OK", nil];
    
             self.callback = callback;
             [alert show];
         }
    
     }
    
     - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
     {
         if (self.callback) {
             if (buttonIndex == alertView.cancelButtonIndex) {
               // Authorization is allowed for the user. The callback parameter is 0.
               self.callback(0);
             }else{
               // Authorization is allowed for the user. The callback parameter is 1.
               self.callback(1);
             }
         }
    
     }