当前位置:网站首页>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 了 .


边栏推荐
- “東數西算”下數據中心的液冷GPU服務器如何發展?
- NLP自然语言处理-机器学习和自然语言处理介绍(一)
- Solution to schema verification failure in saving substantive examination request
- 数字经济“双碳”目标下,“东数西算”数据中心为何依靠液冷散热技术节能减排?
- How to build a liquid cooling data center is supported by blue ocean brain liquid cooling technology
- Interpretation of the paper: develop a prediction model based on multi-layer deep learning to identify DNA N4 methylcytosine modification
- NLP自然语言处理-机器学习和自然语言处理介绍(二)
- 单片机学习笔记5--STM32时钟系统(基于百问网STM32F103系列教程)
- Interpretation of the paper: a convolutional neural network for identifying N6 methyladenine sites in rice genome using dinucleotide one hot encoder
- A hundred schools of thought contend at the 2021 trusted privacy computing Summit Forum and data security industry summit
猜你喜欢

论文解读:《利用注意力机制提高DNA的N6-甲基腺嘌呤位点的鉴定》

利用google or-tools 求解数独难题

Nt68661 screen parameter upgrade-rk3128-start up and upgrade screen parameters yourself

钢结构基本原理试题及答案

2021可信隐私计算高峰论坛暨数据安全产业峰会上百家争鸣

Data analysis of time series (III): decomposition of classical time series

A hundred schools of thought contend at the 2021 trusted privacy computing Summit Forum and data security industry summit

Interpretation of the paper: develop and verify the deep learning system to classify the etiology of macular hole and predict the anatomical results

NLP自然语言处理-机器学习和自然语言处理介绍(二)

钢结构基本原理题库
随机推荐
UE4 solves the problem that the WebBrowser cannot play H.264
高电压技术基础知识
硬件知识1--原理图和接口类型(基于百问网硬件操作大全视频教程)
深度卷积生成对抗网络
The green data center "counting from the east to the west" was fully launched
单片机学习笔记1--资料下载、环境搭建(基于百问网STM32F103系列教程)
How to develop the computing power and AI intelligent chips in the data center of "digital computing in the East and digital computing in the west"?
使用pycaret来进行数据挖掘:关联规则挖掘
All kinds of ice! Use paddegan of the propeller to realize makeup migration
NLP自然语言处理-机器学习和自然语言处理介绍(一)
高电压技术考题附答案
Connaissance du matériel 1 - schéma et type d'interface (basé sur le tutoriel vidéo complet de l'exploitation du matériel de baiman)
绿色数据中心:风冷GPU服务器和水冷GPU服务器综合分析
利用google or-tools 求解逻辑难题:斑马问题
单片机学习笔记7--SysTick定时器(基于百问网STM32F103系列教程)
2021信息科学Top10发展态势。深度学习?卷积神经网络?
高分子合成工艺学复习考题
《高分子合成工艺》简答题答案
单片机学习笔记3--单片机结构和最小系统(基于百问网STM32F103系列教程)
The use of padding.nn.bceloss