diff --git a/Classes/UnityAppController.mm b/Classes/UnityAppController.mm index 552b737..e841d0f 100644 --- a/Classes/UnityAppController.mm +++ b/Classes/UnityAppController.mm @@ -80,6 +80,12 @@ bool _supportsMSAA = false; NSInteger _forceInterfaceOrientationMask = 0; #endif +@interface UnityAppController () + @property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskIdentifier; +@end +static NSString *const kBgTaskName = @"cebg.AppRunInBackground"; + + @implementation UnityAppController @synthesize unityView = _unityView; @@ -293,6 +299,12 @@ extern "C" void UnityRequestQuit() - (void)applicationDidEnterBackground:(UIApplication*)application { ::printf("-> applicationDidEnterBackground()\n"); + self.backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:kBgTaskName expirationHandler:^{ + if (self.backgroundTaskIdentifier != UIBackgroundTaskInvalid) { + [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier]; + self.backgroundTaskIdentifier = UIBackgroundTaskInvalid; + } + }]; } - (void)applicationWillEnterForeground:(UIApplication*)application @@ -305,6 +317,7 @@ extern "C" void UnityRequestQuit() // if we were showing video before going to background - the view size may be changed while we are in background [GetAppController().unityView recreateRenderingSurfaceIfNeeded]; } + [[UIApplication sharedApplication] endBackgroundTask: self.backgroundTaskIdentifier]; } - (void)applicationDidBecomeActive:(UIApplication*)application diff --git a/Info.plist b/Info.plist index da0ff16..6357dd1 100644 --- a/Info.plist +++ b/Info.plist @@ -2,6 +2,8 @@ + UIApplicationExitsOnSuspend + CADisableMinimumFrameDuration CFBundleDevelopmentRegion diff --git a/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate b/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate index e346a99..2f56fa1 100644 Binary files a/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate and b/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 4f4b9f7..463f739 100644 --- a/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -98,5 +98,85 @@ landmarkType = "7"> + + + + + + + + + + + + + + + + + + + + diff --git a/js/main.js b/js/main.js index f8d7a59..7d6df82 100644 --- a/js/main.js +++ b/js/main.js @@ -1,27 +1,37 @@ -console.log('>>hi tiny wallet3') +console.log('>>begin load wallet main file'); /** * 初始化钱包, 所有操作进行前, 必须调用此方法 + * @param {string} type: 钱包类型, 0: 内置钱包, 1: 第三方钱包 * @param {string} password: 用于加密钱包数据的密码 */ -function initWallet(funId, password) { +function initWallet(funId, type, password) { try { var wallet; if ( !window.jc || !jc.wallet ) { - wallet = new jcwallet.default({chain: 322, type: 1, password}); + wallet = new jcwallet.default({chain: 322, type, password}); } else { wallet = jc.wallet; } - console.log('wallet inited, begin connect') - wallet.wConnect.connect() - .then(() => { - console.log(' walletconnect inited') - }) -// let address = jc.wallet.currentAccount().address - return JSON.stringify({errcode: 0, data: ''}); + type = parseInt(type); + if (type === 1) { + console.log('wallet inited, begin connect') + wallet.wConnect.connect() + .then(() => { + console.log('walletconnect inited') + var account = jc.wallet.currentAccount(); + jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: account})); + }) + .catch(err => { + jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err})); + }) + } else { + let address = jc.wallet.currentAccount().address + jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: address})); + } } catch(err) { console.error('error init wallet: ' + JSON.stringify(err)); - return JSON.stringify({errcode: 1, errmsg: err}); + jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err})); } } /** diff --git a/js/platform.js b/js/platform.js index 0359778..cab642c 100644 --- a/js/platform.js +++ b/js/platform.js @@ -8,11 +8,9 @@ window.jumpToWallet = function(url) { url = url || 'wc://'; url = `https://metamask.app.link/wc?uri=${encodeURIComponent(url)}`; console.log('open native: ' + url); - setTimeout(function() { - jsb.reflection.callStaticMethod( - 'UnityAppController', - 'toWallet:', - url - ) - }, 6000) + jsb.reflection.callStaticMethod( + 'UnityAppController', + 'toWallet:', + url + ) }