GRVMapCustomAPIKeyDelegate

In the IAPMiniProgram SDK, if a mini program does not provide a Google API key, your app API key is used by default. To avoid charging your app unreasonable fees on Google Maps service that is used in specific mini programs, you need to prevent the mini programs from using your app API key. Follow this topic to avoid using your app API key.

Procedures

To prevent the mini programs from using your app API key, follow these steps:

Step 1. Implement the GRVMapCustomAPIKeyDelegate delegate

Implement the GRVMapCustomAPIKeyDelegate delegate and write code in the required methods according to your business logic.

Code sample as follows:

copy
class DemoCustomAPIKeyDelegate: NSObject, GRVMapCustomAPIKeyDelegate {
    func canUseGoogleAPIKey(forApp appId: String) -> Bool {
        
    }
}

Step 2. Configure the GRVMapCustomAPIKeyDelegate delegate

Refer to the following sample code. Configure the GRVExtensionDelegate interface to register the GRVMapCustomAPIKeyDelegate delegate after initializing the SDK.

copy
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.alertDelegate = DemoAlertDelegateImpl()

Delegates

GRVMapCustomAPIKeyDelegate delegate

The definition of the GRVMapCustomAPIKeyDelegate protocol is shown in the following codes:

copy
@protocol GRVMapCustomAPIKeyDelegate <NSObject>

/// This method allows you to disable certain mini program from using your Google API key.
/// Default value is YES if this delegate is not implemented.
- (BOOL)canUseGoogleAPIKeyForApp:(NSString *)appId;

@end

Methods

Based on the definition above, this delegate provides the following method:

canUseGoogleAPIKeyForApp: method

Parameters

Field

Data type

Required

Description

appId

String

Yes

The mini program appId.

Return value

Field

Data type

Required

Description

N/A

BOOL

Yes

Return the result of whether the current appId can use Google API key