Commit bc89e810 authored by chicheng's avatar chicheng

IOS插件加载问题解决

parent 9193e928
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import { import {
mapMutations mapMutations
} from 'vuex' } from 'vuex'
const nativePlugin = uni.requireNativePlugin("UUMbsAgentPlugin-Test")
export default { export default {
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
...@@ -20,11 +19,34 @@ ...@@ -20,11 +19,34 @@
onShow: function() { onShow: function() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
setTimeout(function() { // 被唤醒获取参数 需异步一下 setTimeout(() => { // 被唤醒获取参数 需异步一下
try { try {
const args = plus.runtime.arguments const args = plus.runtime.arguments
if (plus.runtime.arguments && typeof args === 'string') { if (args && typeof args === 'string') {
const data = nativePlugin.handleOpenURL(args) // 只在有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) { } catch (e) {
console.error('handleOpenURL error:', e) console.error('handleOpenURL error:', e)
......
...@@ -84,7 +84,39 @@ ...@@ -84,7 +84,39 @@
getIdToken getIdToken
} from '@/servers/user.js' } 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 { export default {
data() { data() {
return { return {
...@@ -129,12 +161,18 @@ ...@@ -129,12 +161,18 @@
} }
}, },
onLoad() { onLoad() {
ToastPlusModule && this.initEx() const ToastPlusModule = getNativePlugin()
if (ToastPlusModule) {
this.initEx()
}
}, },
onShow() { onShow() {
// 判断是否正在等待authEx的返回结果,第一次进入页面默认是false // 判断是否正在等待authEx的返回结果,第一次进入页面默认是false
if (!this.flag && !this.accessToken) { if (!this.flag && !this.accessToken) {
ToastPlusModule && this.authEx() const ToastPlusModule = getNativePlugin()
if (ToastPlusModule) {
this.authEx()
}
} }
}, },
//页面初始加载 //页面初始加载
...@@ -157,17 +195,25 @@ ...@@ -157,17 +195,25 @@
}, },
methods: { methods: {
initEx(){ initEx(){
const ToastPlusModule = getNativePlugin()
if (!ToastPlusModule) {
console.warn('Native plugin not available for initEx')
return
}
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}); });
try { try {
// 调用同步方法 // 调用同步方法
if (typeof ToastPlusModule.registerSyncFunc === 'function') {
var obj = ToastPlusModule.registerSyncFunc({ var obj = ToastPlusModule.registerSyncFunc({
appKey: 'com.wuliangye.emobilewlycrm', appKey: 'com.wuliangye.emobilewlycrm',
secretKey: '9ab24ae4bfb349cca739ab15b78f1c7f8737eb73', secretKey: '9ab24ae4bfb349cca739ab15b78f1c7f8737eb73',
packageName: 'com.uusafe.portal.wly' packageName: 'com.uusafe.portal.wly'
}) })
console.log(obj) console.log(obj)
}
} catch (e) { } catch (e) {
console.error('initEx error:', e) console.error('initEx error:', e)
} finally { } finally {
...@@ -204,6 +250,12 @@ ...@@ -204,6 +250,12 @@
this.$refs.password.blur() this.$refs.password.blur()
}, },
authEx(){ authEx(){
const ToastPlusModule = getNativePlugin()
if (!ToastPlusModule) {
console.warn('Native plugin not available for authEx')
return
}
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}); });
...@@ -218,7 +270,7 @@ ...@@ -218,7 +270,7 @@
}, 5000) }, 5000)
try { try {
if (ToastPlusModule && typeof ToastPlusModule.registerExSyncFunc === 'function') { if (typeof ToastPlusModule.registerExSyncFunc === 'function') {
ToastPlusModule.registerExSyncFunc({}, res => { ToastPlusModule.registerExSyncFunc({}, res => {
clearTimeout(timeoutId) clearTimeout(timeoutId)
this.flag = false this.flag = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment