var opts = {api_name: '', // Name of the APIsuccess: function(res) {},fail: function(res) {},complete: function(res) {},data: { // Input Parametersname : 'kka',age : 22,data: {...}}}wx.invokeNativePlugin(opts); // Invocation
Method | Description |
View onCreateLoadingView() | Create a loading view, permitting the host client to render mini program/mini game brand and custom display styles. If returned as null, the default loading view will be exhibited. |
View onCreateCapsuleView() | Establish a capsule button, allowing the host to customize the capsule button style. If returned as null, the default capsule button will be displayed. |
boolean onShowMenu() | Triggered when the "..." more button is clicked. If onCreateCapsuleView returns null and onShowMenu returns false, the default menu will be displayed. |
void onExit() | Activated when the "〇" exit button is clicked. If onCreateCapsuleView returns null and onExit returns false, the default operation will be executed. |
boolean onAuthorize(JSONObject params, Value Callback callback) | Implementation of the wx.authorize interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onOpenSetting(JSONObject params, ValueCallback callback) | Implementation of the wx.openSetting interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onGetSetting(JSONObject params, ValueCallback callback) | Implementation of the wx.getSetting interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onLogin(JSONObject params, ValueCallback callback) | Implementation of the wx.login interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onRefreshSession(JSONObject params, ValueCallback callback) | Implementation of the wx.checkSession interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onRequestPayment(JSONObject params, ValueCallback callback) | Implementation of the wx.requestPayment interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onGetUserInfo(JSONObject params, ValueCallback callback) | Implementation of the wx.getUserInfo interface. If it returns false, the notification of wx api call failure will be directly sent. For more details, see onGetUserInfo. |
boolean onShareAppMessage(JSONObject params, ValueCallback callback) | Implementation of the wx.shareAppMessage interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onNavigateToMiniProgram(JSONObject params, ValueCallback callback) | Implementation of the wx.navigateToMiniProgram interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onScanCode(JSONObject params, ValueCallback callback) | Implementation of the wx.scanCode interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onOpenDocument(JSONObject params, ValueCallback callback) | Implementation of the wx.openDocument interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onOpenLocation(JSONObject params, ValueCallback callback) | Implementation of the wx.openLocation interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onChooseLocation(JSONObject params, ValueCallback callback) | Implementation of the wx.chooseLocation interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onPreviewImage(JSONObject params, ValueCallback callback) | Implementation of the wx.rviewImage interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onChooseImage(JSONObject params, ValueCallback callback) | Implementation of the wx.chooseImage interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onChooseVideo(JSONObject params, ValueCallback callback) | Implementation of the wx.chooseVideo interface. If it returns false, the notification of wx api call failure will be directly sent. |
boolean onShowToast(JSONObject params, ValueCallback callback) | Implementation of the wx.showToast and wx.showLoading interfaces. If it returns false, the default style will be displayed. |
boolean onHideToast(JSONObject params, ValueCallback callback) | Implementation of the wx.hideToast and wx.hideLoading interfaces. If it returns false, the default style will be displayed. |
boolean onShowModal(JSONObject params, ValueCallback callback) | Implementation of the wx.showModal interface. If it returns false, the default style will be displayed. |
boolean onInvokeWebAPI(String event, JSONObject params, ValueCallback callback) | Implementation of the custom wx api. If it returns false, the notification of wx api call failure will be directly sent. For more details, see onInvokeWebAPI. |
boolean onReportEvent(String event, Map params) |
-(void)onGetUserInfoWithParams:(NSDictionary *)params inApp:(NSString *)appId callbackHandler:(WebAPICallbackHandler)handler {//TODONSDictionary* userInfo = @{@"nickname" : @"morven",@"headimgurl" : @"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKav1ib8qG43xy0resTpgfeCqH00vRpHicEdk0kKMxqTMMUG1WmBuAdgB2tmCf6joGVKlGbsicelhluw/0",@"sex" : @(1),@"province" : @"Guangdong",@"city" : @"Shenzhen",@"country" : @"China"};NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:1];NSMutableDictionary* userInfoDic = [NSMutableDictionary dictionaryWithCapacity:6];NSMutableDictionary* resultDataDic = [NSMutableDictionary dictionaryWithCapacity:1];[userInfoDic setValue:userInfo[@"nickname"] forKey:@"nickName"];[userInfoDic setValue:userInfo[@"headimgurl"] forKey:@"avatarUrl"];[userInfoDic setValue:userInfo[@"sex"] forKey:@"gender"];[userInfoDic setValue:userInfo[@"province"] forKey:@"province"];[userInfoDic setValue:userInfo[@"city"] forKey:@"city"];[userInfoDic setValue:userInfo[@"country"] forKey:@"country"];NSData *data=[NSJSONSerialization dataWithJSONObject:userInfoDic options:NSJSONWritingPrettyPrinted error:nil];[resultDataDic setValue:[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding] forKey:@"data"];[result setValue:resultDataDic forKey:@"data"];[result setValue:@"getUserInfo:ok" forKey:@"errMsg"];if (handler) {//successhandler(result, nil);}}
- (BOOL)onInvokeWebAPIWithEvent:(NSString*)event params:(NSDictionary*)params callbackHandler:(WebAPICallbackHandler _Nullable)handler {NSLog(@"onInvokeWebAPIWithEvent, event:%@, params:%@", event, params);if (handler) {handler(@{@"errMsg" : @"onInvokeWebAPIWithEvent"}, nil);}return YES;}
Event reporting. The events are as follows:1. Launch the mini program, event: MS_EVENT_LAUNCH, keys for params: pagePath, d;2. Duration of mini program usage, event: MS_EVENT_USE_TIME, keys for params: useTime, startId, appId; the unit of useTime is milliseconds;3. Successful launch of the mini program, event: MS_EVENT_LAUNCH_SUCCESS, keys for params: appId.4. Opening a page within the mini program, event: MS_EVENT_OPEN_PAGE, keys for params: pagePath, appId.5. Failure to launch the mini program, event: MS_EVENT_LAUNCH_FAIL, keys for params: pagePath, reason, appId.
Was this page helpful?