Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
wly-APP
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘川
wly-APP
Commits
bc89e810
Commit
bc89e810
authored
Jan 13, 2026
by
chicheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS插件加载问题解决
parent
9193e928
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
14 deletions
+88
-14
App.vue
App.vue
+26
-4
login.nvue
pages/login/login.nvue
+62
-10
No files found.
App.vue
View file @
bc89e810
...
...
@@ -2,7 +2,6 @@
import
{
mapMutations
}
from
'vuex'
const
nativePlugin
=
uni
.
requireNativePlugin
(
"UUMbsAgentPlugin-Test"
)
export
default
{
onLaunch
:
function
()
{
console
.
log
(
'App Launch'
)
...
...
@@ -20,11 +19,34 @@
onShow
:
function
()
{
// #ifdef APP-PLUS
setTimeout
(
function
()
{
// 被唤醒获取参数 需异步一下
setTimeout
(
()
=>
{
// 被唤醒获取参数 需异步一下
try
{
const
args
=
plus
.
runtime
.
arguments
if
(
plus
.
runtime
.
arguments
&&
typeof
args
===
'string'
)
{
const
data
=
nativePlugin
.
handleOpenURL
(
args
)
if
(
args
&&
typeof
args
===
'string'
)
{
// 只在有URL参数需要处理时才获取插件(从其他应用唤醒时)
// iOS平台:如果插件不可用,静默跳过,不影响应用运行
// #ifdef APP-IOS
try
{
const
nativePlugin
=
uni
.
requireNativePlugin
(
"UUMbsAgentPlugin-Test"
)
if
(
nativePlugin
&&
typeof
nativePlugin
.
handleOpenURL
===
'function'
)
{
nativePlugin
.
handleOpenURL
(
args
)
}
}
catch
(
pluginError
)
{
// iOS平台插件不可用时,静默跳过,不输出错误(避免首页报错)
// console.warn('iOS native plugin not available:', pluginError)
}
// #endif
// #ifdef APP-ANDROID
try
{
const
nativePlugin
=
uni
.
requireNativePlugin
(
"ToastPlus"
)
||
uni
.
requireNativePlugin
(
"UUMbsAgentPlugin-Test"
)
if
(
nativePlugin
&&
typeof
nativePlugin
.
handleOpenURL
===
'function'
)
{
nativePlugin
.
handleOpenURL
(
args
)
}
}
catch
(
pluginError
)
{
console
.
warn
(
'Android native plugin error:'
,
pluginError
)
}
// #endif
}
}
catch
(
e
)
{
console
.
error
(
'handleOpenURL error:'
,
e
)
...
...
pages/login/login.nvue
View file @
bc89e810
...
...
@@ -84,7 +84,39 @@
getIdToken
} from '@/servers/user.js'
const ToastPlusModule = uni.requireNativePlugin("ToastPlus") || uni.requireNativePlugin("UUMbsAgentPlugin-Test")
// 安全获取原生插件,避免iOS平台初始化失败影响应用运行
const getNativePlugin = () => {
// #ifdef APP-IOS
// iOS平台:如果插件不可用,返回null,不抛出错误
try {
const plugin = uni.requireNativePlugin("UUMbsAgentPlugin-Test")
// 检查插件是否有效(避免返回无效对象)
if (plugin && (typeof plugin.registerSyncFunc === 'function' || typeof plugin.registerExSyncFunc === 'function')) {
return plugin
}
return null
} catch (e) {
// iOS平台插件初始化失败时,静默返回null,不输出错误
// 这样可以避免在首页或其他页面加载时显示错误提示
return null
}
// #endif
// #ifdef APP-ANDROID
// Android平台:正常获取插件
try {
return uni.requireNativePlugin("ToastPlus") || uni.requireNativePlugin("UUMbsAgentPlugin-Test")
} catch (e) {
console.warn('Android native plugin not available:', e)
return null
}
// #endif
// #ifndef APP-PLUS
return null
// #endif
}
export default {
data() {
return {
...
...
@@ -129,12 +161,18 @@
}
},
onLoad() {
ToastPlusModule && this.initEx()
const ToastPlusModule = getNativePlugin()
if (ToastPlusModule) {
this.initEx()
}
},
onShow() {
// 判断是否正在等待authEx的返回结果,第一次进入页面默认是false
if (!this.flag && !this.accessToken) {
ToastPlusModule && this.authEx()
const ToastPlusModule = getNativePlugin()
if (ToastPlusModule) {
this.authEx()
}
}
},
//页面初始加载
...
...
@@ -157,17 +195,25 @@
},
methods: {
initEx(){
const ToastPlusModule = getNativePlugin()
if (!ToastPlusModule) {
console.warn('Native plugin not available for initEx')
return
}
uni.showLoading({
title: '加载中'
});
try {
// 调用同步方法
var obj = ToastPlusModule.registerSyncFunc({
appKey: 'com.wuliangye.emobilewlycrm',
secretKey: '9ab24ae4bfb349cca739ab15b78f1c7f8737eb73',
packageName: 'com.uusafe.portal.wly'
})
console.log(obj)
if (typeof ToastPlusModule.registerSyncFunc === 'function') {
var obj = ToastPlusModule.registerSyncFunc({
appKey: 'com.wuliangye.emobilewlycrm',
secretKey: '9ab24ae4bfb349cca739ab15b78f1c7f8737eb73',
packageName: 'com.uusafe.portal.wly'
})
console.log(obj)
}
} catch (e) {
console.error('initEx error:', e)
} finally {
...
...
@@ -204,6 +250,12 @@
this.$refs.password.blur()
},
authEx(){
const ToastPlusModule = getNativePlugin()
if (!ToastPlusModule) {
console.warn('Native plugin not available for authEx')
return
}
uni.showLoading({
title: '加载中'
});
...
...
@@ -218,7 +270,7 @@
}, 5000)
try {
if (
ToastPlusModule &&
typeof ToastPlusModule.registerExSyncFunc === 'function') {
if (typeof ToastPlusModule.registerExSyncFunc === 'function') {
ToastPlusModule.registerExSyncFunc({}, res => {
clearTimeout(timeoutId)
this.flag = false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment