Integrate SDK components
By integrating iOS IAPMiniProgram SDK, the basic capabilities of mini-programs are included in your project. However, due to package size and App Store reviewing concerns, enhanced capabilities of iOS IAPMiniProgram SDK are not included by default.
You can enhance the SDK capabilities by integrating the following pre-defined SDK components:
- Map: With this component integrated into your app, users can implement the Google Map capabilities in your mini-programs. For more information, see Integrate the Map component.
- Video: With this component integrated into your app, users can play videos in your mini-programs. For more information, see Integrate the Video component.
- Lottie: With this component integrated into your app, users can implement the Lottie capabilities in your mini-programs. For more information, see Integrate the Lottie component.
- Livestreaming: With this component integrated into your app, users can play live-streaming videos in your mini-programs. For more information, see Integrate the Livestreaming component.
- Bluetooth: With this component integrated into your app, users can implement the Bluetooth capabilities in your mini-programs. For more information, see Integrate the Bluetooth component.
Note: If a component is not integrated, the mini-program encounters the error code
1
(JSAPI not existed
) when calling JSAPIs related to the component.
Integrate the Map component
To allow users to evoke a map in your mini-programs, you need to integrate the Map component into your project. For iOS users, two maps are supported to be integrated:
- Google Maps: Read this section to learn about how to integrate Google Maps into your app.
- Apple Maps: Read this section to learn about how to integrate Apple Maps into your app.
Google Maps
Step 1: Add a key to the plist file
Due to the limitations of the iOS system, you must add a specific key with a privacy description to the plist file before using the capabilities. For example, to use location capabilities, you must add the following keys:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>...</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>...</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>...</string>
Step 2: Import the Map component
Then, you need to import the Map component of iOS IAPMiniProgram SDK into your project. Refer to the following sample code:
let configuration = GRVConfiguration()
configuration.apiKeyForGoogleMaps = "YOUR_API_KEY"
// Make sure your default coordinates are relevant
configuration.defaultCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0)
When using the sample code above, take the following things into consideration:
- Package size: The Map component contributes approximately 426 KB to your binary product (arm64 arch).
- Properties: When initializing IAPMiniProgram SDK, two properties of
GRVConfiguration
(apiKeyForGoogleMaps and defaultCoordinate) must be set correctly:
- apiKeyForGoogleMaps: Indicates the Google API key that is required for using Google Maps. To get a Google API key, see Using API Keys in Google's documentation.
- defaultCoordinate: Indicates the default coordinates, including latitude and longitude. Make sure your default coordinates are relevant.
(Optional) Step 3: Prevent specific mini-programs from using your app's API key
If a mini-program does not provide a Google API key, your app's API key is used by default. To avoid charging your app unreasonable fees on Google Maps services used in specific mini-programs, you need to prevent the mini-programs from using your app's API key.
Implement GRVMapCustomAPIKeyDelegate
with the following code:
class DemoCustomAPIKeyDelegate: NSObject, GRVMapCustomAPIKeyDelegate {
func canUseGoogleAPIKey(forApp appId: String) -> Bool {
return false
}
}
More information
For more information about the Map components, see the following documents:
Apple Maps
To allow users to evoke Apple Maps in your mini-programs, update your Podfile with the following code:
pod 'IAPMiniProgram/AppleMap'
For more information about the Map-related JSAPI, see my.createMapContext.
Integrate the Video component
To allow users to play videos in your mini-programs, you need to integrate the Video component into your project.
Update your Podfile with the following code:
pod 'IAPMiniProgram/Video'
For more information about the Video component, see my.createVideoContext.
Integrate the Lottie component
To allow users to implement the Lottie capabilities in your mini-programs, you need to integrate the Lottie component into your project.
Update your Podfile with the following code:
pod 'IAPMiniProgram/Lottie'
For more information about the Map-related JSAPI, see my.createMapContext.
Integrate the Livestreaming component
To allow users to play live-streaming videos in your mini-programs, you need to integrate the Livestreaming component into your project.
Update your Podfile with the following code:
pod 'IAPMiniProgram/Media'
For more information about the Livestreaming component, see my.createLivePlayerContext.
Integrate the Bluetooth component
To allow users to implement the Bluetooth capabilities in your mini-programs, you need to integrate the Bluetooth component into your project.
Update your Podfile with the following code:
pod 'IAPMiniProgram/Bluetooth'
For more information about the Bluetooth component, see Bluetooth JSAPIs.