当前位置:网站首页>Uni native plug-in development -- Youmeng one click login
Uni native plug-in development -- Youmeng one click login
2022-07-23 12:23:00 【Try to be a charterer】
Native plug-in development -- Youmeng one click login (UMVerify)
umeng SDK Get ready
download UMVerify SDK
Manually integrate Youmeng SDK, Open the official website of Youmeng , Select the Developer Center -SDK
After entering, choose the end — Selection platform — Choose products and services for integration 

take SDK Import the project
After downloading
.framework Import into the main project .
.bundle Import to Bundles Under the folder .
Here we need to pay attention to , All the third party's .bundle All documents need to be put here . Otherwise, you can't quote .
First step : download SDK

The second step : Import of the main project framework Inside

The third step :bundle Import to the specific folder of the main project .

umeng SDK The configuration of can be in accordance with the official documents .
Problems encountered
If the following problems occur in the plug-in project , You can follow the steps below to refer to the solution .
1、 problem : The plug-in project references the header file of Youmeng and reports an error , Prompt: the file cannot be found . solve : Will download the header file of Youmeng , Copy all to the plug-in project file , Then put its path in targets—search paths—framework search paths Inside . Pictured


In this way, you can use the header file of Youmeng when compiling and running .
Code calls
iOS End code
Create a new one YMModule file , Inherit DCUniModule. stay YMModule.h Plug ins are introduced into the file 、 Header file required by Youmeng . Here's the picture 
The first header file is inherited by plug-in development , Must write
The second is the header file that Youmeng needs to reference , Must write
The third is for the third party sharing of the alliance .
The three in the box are the header files required for Youmeng one click login .
The first is one click login SDK The header file , Required
The second is the rewriting of Youmeng one click login page style .( Quote according to the actual situation )
The third is the wind and fire wheel .( Quote according to the actual situation )
.m file
@implementation YMModule
// umeng One click login . Macro definitions are used for uniapp call
UNI_EXPORT_METHOD(@selector(UmLoginVerify:callback:))
#pragma mark - One click login js Method called
- (void)UmLoginVerify:(NSDictionary *)options callback:(UniModuleKeepAliveCallback)callback
{
// options by js Parameters passed when calling this method on the client side
// The first parameter is returned to js End data , The second parameter is identification , Indicates whether the callback method supports multiple calls , If the native side needs multiple callbacks js At the end, the second parameter is transmitted to YES;
float timeout = 5.0;
__weak typeof(self) weakSelf = self;
[ProgressHUD show:@" One moment please ..." Interaction:YES];
// Initialize relevant configurations of Youmeng
[UMConfigure initWithAppkey:[options objectForKey:@"UMAppkey"] channel:@"App Store"];
// Set key
NSString*info = [NSString stringWithFormat:@"%@",[options objectForKey:@"VerifySDKInfo"]];
// Set up SDK Parameters ,app It can be called once in the life cycle
[UMCommonHandler setVerifySDKInfo:info complete:^(NSDictionary*_Nonnull resultDic){
NSLog(@"VerifySDKInf=%@",resultDic);
}];
// Check whether the current environment supports one click login , Support knowing in advance (UMPNSAuthTypeLoginToken Check the one click login environment UMPNSAuthTypeVerifyToken Check the number authentication environment )
__block BOOL support = YES;
[UMCommonHandler checkEnvAvailableWithAuthType:UMPNSAuthTypeLoginToken complete:^(NSDictionary*_Nullable resultDic){
support =[PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]];
}];
// Is there a sim card
if ([UMCommonUtils simSupportedIsOK]){
[UMCommonHandler accelerateLoginPageWithTimeout:timeout complete:^(NSDictionary * _Nonnull resultDic) {
if ([PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]] == NO) {
[ProgressHUD showError:@" Take the number , Failed to pop up the acceleration authorization page "];
if (callback) {
callback(resultDic,YES);
}
return ;
}
//2. Call get login Token Interface , You can pop up the authorization page immediately
[ProgressHUD dismiss];
UMCustomModel *model = [weakSelf buildCustomModel:NO];
model.supportedInterfaceOrientations = UIInterfaceOrientationMaskAllButUpsideDown;
[UMCommonHandler getLoginTokenWithTimeout:timeout controller:[YMModule dc_findCurrentShowingViewController] model:model complete:^(NSDictionary * _Nonnull resultDic) {
NSLog(@"logintoken:%@",resultDic);
if (callback) {
callback(resultDic,YES);
}
NSString *code = [resultDic objectForKey:@"resultCode"];
if ([PNSCodeLoginControllerPresentSuccess isEqualToString:code]) {
[ProgressHUD showSuccess:@" Successfully pop up the authorization page "];
} else if ([PNSCodeLoginControllerClickCancel isEqualToString:code]) {
[ProgressHUD showSuccess:@" Click return to the authorization page "];
} else if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:code]) {
[ProgressHUD showSuccess:@" Click the switch other login methods button "];
} else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:code]) {
if ([[resultDic objectForKey:@"isChecked"] boolValue] == YES) {
[ProgressHUD showSuccess:@" Click the login button ,check box Choose ,SDK Internal will then go to get login Token"];
} else {
[ProgressHUD showSuccess:@" Click the login button ,check box Choose ,SDK Internal will not get login Token"];
}
} else if ([PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:code]) {
[ProgressHUD showSuccess:@" Click on check box"];
} else if ([PNSCodeLoginControllerClickProtocol isEqualToString:code]) {
[ProgressHUD showSuccess:@" Click on the protocol rich text "];
} else if ([PNSCodeSuccess isEqualToString:code]) {
// Click the login button Get login Token Successful callback
NSString *token = [resultDic objectForKey:@"token"];
// Take token Go to the server and change your mobile number
// If it is a native function This place can call the server interface .
// Now it's plug-in development , This token It needs to be passed to uniapp 了 .
// Here is the whole result Pass to uniapp.
dispatch_async(dispatch_get_main_queue(), ^{
[UMCommonHandler cancelLoginVCAnimated:YES complete:nil];
});
}
}];
}];
}else {
[self debugLogin:[YMModule dc_findCurrentShowingViewController] model:nil];
}
}
// debug Login method
-(void)debugLogin:(UIViewController *)controller model:(UMCustomModel *)model
// Call up the one click login page
-(UMCustomModel *)buildCustomModel:(BOOL)isAlert
// This is debug Login method , Can not write .
-(void)debugLogin:(UIViewController *)controller model:(UMCustomModel *)model
{
[UMCommonHandler debugLoginUIWithController:controller model:model complete:^(NSDictionary * _Nonnull resultDic) {
}];
}
// This method is to invoke the one click login page
- (UMCustomModel *)buildCustomModel:(BOOL)isAlert {
if (isAlert) {
return [UMModelCreate createAlert];
} else {
return [UMModelCreate createFullScreen];
}
}
// Get the currently displayed UIViewController
+(UIViewController *)dc_findCurrentShowingViewController
+(UIViewController *)findCurrentShowingViewControllerFrom:(UIViewController *)vcbecause module Not included viewcontroller, So it's using viewcontroller The above method is needed where .
such as , The code in the native function is used like this .
[UMCommonHandler getLoginTokenWithTimeout:timeout controller:self model:model complete:^(NSDictionary * _Nonnull resultDic) { }];
there self In the plug-in project, it needs to be changed to [YMModule dc_findCurrentShowingViewController]
The complete code will become
[UMCommonHandler getLoginTokenWithTimeout:timeout controller:[YMModule dc_findCurrentShowingViewController] model:model complete:^(NSDictionary * _Nonnull resultDic) { }];
#pragma mark - obtain viewcontroller
// Get the currently displayed UIViewController
+ (UIViewController *)dc_findCurrentShowingViewController {
// Get the root view of the currently active window
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentShowingVC = [self findCurrentShowingViewControllerFrom:vc];
return currentShowingVC;
}
+ (UIViewController *)findCurrentShowingViewControllerFrom:(UIViewController *)vc
{
// Recursive method Recursive method
UIViewController *currentShowingVC;
if ([vc presentedViewController]) {
// The current view is presented Coming out
UIViewController *nextRootVC = [vc presentedViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
// The root view is UITabBarController
UIViewController *nextRootVC = [(UITabBarController *)vc selectedViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else if ([vc isKindOfClass:[UINavigationController class]]){
// The root view is UINavigationController
UIViewController *nextRootVC = [(UINavigationController *)vc visibleViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else {
// The root view is a non navigational class
currentShowingVC = vc;
}
return currentShowingVC;
}
@end
iOS Data returned after successful login
Log in successfully , Get token Parameters will be returned where . According to what I got token value , Request server interface , To verify .
{
carrierFailedResultData = {
};
innerCode = 103000;
innerMsg = “”;
msg = “”;
requestId = c724a6248bd64c3f;
resultCode = 600000;
token = 123456;
}
uniapp End code
<template>
<div>
<button type="primary" @click="testAsyncFunc">testAsyncFunc</button>
<button type="primary" @click="testSyncFunc">testSyncFunc</button>
<button type="primary" @click="testUmLoginVerify">testUmLoginVerify</button>
</div>
</template>
<script> // First we need to pass uni.requireNativePlugin("ModuleName") obtain module var testModule = uni.requireNativePlugin("cymtestPlugins-YMModule") export default {
methods: {
testAsyncFunc() {
// Call asynchronous methods testModule.testAsyncFunc({
'name': 'uni-app', 'age': 1 }, (ret) => {
uni.showToast({
title:'cym-demo- Call asynchronous methods ' + ret, icon: "none" }) }) }, testSyncFunc() {
// Call the synchronization method var ret = testModule.testSyncFunc({
'name': 'uni-app', 'age': 1 }) uni.showToast({
title:' Call the synchronization method cym ' + ret, icon: "none" }) } testUmLoginVerify(){
testModule.UmLoginVerify({
'UMAppkey': '59892ebcaed179694b000104', 'VerifySDKInfo': 'WPsC0MdV+g0nHmn1HdpGlPp1aiL6IM8oTjxG0DI89yFBhYp7mTTOQOMSJJMcbiIGd+6XdDs8pILvvklioVfVGkUYsULKoIlh1UqWwNl9LRXW6/jgK55oxgPk20vffYdc85XTPtU8BacNSJgyItD1WXh2DryPX7RQoPW3vJyKVmPv3LH3XAd5MVvjsWHtTW30nF1ZySe5WMRyE7q7MTAJsfEBe2Fa3P6KQNffAA2fGcaM7d0aOnFAoD6MgxaGSoph/vAvDpDiW4A=' }, (ret) => {
uni.showToast({
title:'cym-demo-UmLoginVerify, Get token ' + ret.token, icon: "none" }) }) } } } </script>
Local run debugging
Be careful uniapp The package name after packaging needs to be consistent with iOS Inside control In the document appid bring into correspondence with .
uniapp Inside 
iOS Inside 
uniapp Export local package 
Pay attention here , The use of HBuilder X Tools should be consistent with iOS In the plug-in SDK Keep the version . Otherwise, the operation will report an error . Unification here is the latest 3.4.18 edition .
Click this path to get the latest local package , Pull the bag to iOS Inside the project .
So we can run iOSAPP 了 .


边栏推荐
- Summary of problems encountered during app audit
- NLP自然语言处理-机器学习和自然语言处理介绍(一)
- 高分子物理考研概念及要点、考点总结
- 高分子物理名词解释
- The online seminar on how to help data scientists improve data insight was held on June 8
- 绿色数据中心:风冷GPU服务器和水冷GPU服务器综合分析
- NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road
- 硬件知识2--协议类(基于百问网硬件操作大全视频教程)
- 数据分析(一)
- Six trends and eight technologies of high-performance computing in data centers under "data center white paper 2022" and "computing from the east to the west"
猜你喜欢

论文解读:《基于BERT和二维卷积神经网络的DNA增强子序列识别transformer结构》

利用or-tools来求解路径规划问题(VRP)

钢结构基本原理题库

高分子物理名词解释归纳

Using or tools to solve the path planning problem with capacity constraints (CVRP)

Interpretation of the paper: a convolutional neural network for identifying N6 methyladenine sites in rice genome using dinucleotide one hot encoder

Check the sandbox file in the real app

单片机学习笔记4--GPIO(基于百问网STM32F103系列教程)

论文解读:《基于预先训练的DNA载体和注意机制识别增强子-启动子与神经网络的相互作用》

The green data center "counting from the east to the west" was fully launched
随机推荐
NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road
C语言中,对柔性数组的理解
高电压技术学习总结
线性规划之Google OR-Tools 简介与实战
How to establish data analysis thinking
Eigen multi version library installation
Deep convolution generation countermeasure network
Data analysis (I)
Matplotlib Usage Summary
利用pycaret:低代码,自动化机器学习框架解决回归问题
Solution to schema verification failure in saving substantive examination request
钢结构基本原理试题及答案
Six trends and eight technologies of high-performance computing in data centers under "data center white paper 2022" and "computing from the east to the west"
液冷数据中心如何构建,蓝海大脑液冷技术保驾护航
Read and write file data
Development and deployment of steel defect detection using paddlex yolov3 of propeller
《高分子合成工艺》简答题答案
Importance of data analysis
使用PyOD来进行异常值检测
数字经济“双碳”目标下,“东数西算”数据中心为何依靠液冷散热技术节能减排?