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.
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:
Custom display
mPaaS supports the display of custom permission popups, you can set it through the interface in the image below.
The implementation steps are as follows:
After the container is initialized, specify the delegate of the custom permission popup.
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Mini Program API Permission Control
[TAAuthorizeStorageManager shareInstance].authorizeAlertDelegate = self;
...
}
Implement custom popup method.
#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) {
// The user allows authorization, the callback parameter is 0
self.callback(0);
}else{
// The user allows authorization, the callback parameter is 1
self.callback(1);
}
}
}