cocos 3.17 lua的切换前后台在ios上处理

崩溃日志如下:
{“app_name”:“CloudVoiceRealTimeVoiceLua2-mobile”,“timestamp”:“2019-03-28 17:25:57.28 +0800”,“app_version”:"",“slice_uuid”:“c270fdc6-2a4f-3bf4-af11-e36d76034448”,“adam_id”:0,“build_version”:“1.0”,“bundleID”:“com.cloudvoice.realtimevoice.lua.demo”,“share_with_app_devs”:true,“is_first_party”:false,“bug_type”:“109”,“os_version”:“iPhone OS 11.3.1 (15E302)”,“incident_id”:“AF15C83B-3EC5-4ED1-8637-C3D2CE0E66FD”,“name”:“CloudVoiceRealTimeVoiceLua2-mobile”}
Incident Identifier: AF15C83B-3EC5-4ED1-8637-C3D2CE0E66FD
CrashReporter Key: 32b29100fcf9be7722e44cd48dc5589390da3524
Hardware Model: iPhone8,1
Process: CloudVoiceRealTimeVoiceLua2-mobile [3963]
Path: /private/var/containers/Bundle/Application/CFAB75D7-F4B8-47EC-B98C-DE34273CF7A3/CloudVoiceRealTimeVoiceLua2-mobile.app/CloudVoiceRealTimeVoiceLua2-mobile
Identifier: com.cloudvoice.realtimevoice.lua.demo
Version: 1.0
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.cloudvoice.realtimevoice.lua.demo [7633]

Date/Time: 2019-03-28 17:25:56.7897 +0800
Launch Time: 2019-03-28 17:14:40.7065 +0800
OS Version: iPhone OS 11.3.1 (15E302)
Baseband Version: 4.56.00
Report Version: 104

Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Termination Description: SPRINGBOARD, scene-update watchdog transgression: com.cloudvoice.realtimevoice.lua.demo exhausted real (wall clock) time allowance of 10.00 seconds | | ProcessVisibility: Background | ProcessState: Running | WatchdogEvent: scene-update | WatchdogVisibility: Foreground | WatchdogCPUStatistics: ( | “Elapsed total CPU time (seconds): 0.840 (user 0.840, system 0.000), 48% CPU”, | “Elapsed application CPU time (seconds): 0.002, 0% CPU” | )
Triggered by Thread: 0

Filtered syslog:
None found

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000181143e08 0x181143000 + 3592
1 libsystem_kernel.dylib 0x0000000181143c80 0x181143000 + 3200
2 AudioToolbox 0x000000018545e508 0x1851f9000 + 2512136
3 AudioToolbox 0x00000001852b2e84 0x1851f9000 + 761476
4 AudioToolbox 0x00000001852b2504 0x1851f9000 + 759044
5 AudioToolbox 0x000000018564304c 0x1851f9000 + 4497484
6 AudioToolbox 0x0000000185340de0 0x1851f9000 + 1342944
7 AudioToolbox 0x000000018556dfe4 0x1851f9000 + 3624932
8 AudioToolbox 0x00000001854ece94 0x1851f9000 + 3096212
9 AudioToolbox 0x00000001854e6e64 0x1851f9000 + 3071588
10 AudioToolbox 0x00000001854e6d10 0x1851f9000 + 3071248
11 OpenAL 0x000000019895fe60 0x19895a000 + 24160
12 OpenAL 0x000000019895fe88 0x19895a000 + 24200
13 OpenAL 0x0000000198962e3c 0x19895a000 + 36412
14 …iceRealTimeVoiceLua2-mobile 0x0000000102fea634 -[CDSoundEngine dealloc] + 284
15 …iceRealTimeVoiceLua2-mobile 0x00000001031e1e60 -[CDAudioManager dealloc] + 60
16 …iceRealTimeVoiceLua2-mobile 0x00000001031e2c08 +[CDAudioManager end] + 32
17 …iceRealTimeVoiceLua2-mobile 0x0000000102fd988c +[SimpleAudioEngine end] + 40
18 …iceRealTimeVoiceLua2-mobile 0x00000001031907d0 CocosDenshion::SimpleAudioEngine::end+ 3999696 () + 76
19 …iceRealTimeVoiceLua2-mobile 0x0000000102e1d66c lua_cocos2dx_cocosdenshion_SimpleAudioEngine_end+ 382572 (lua_State*) + 76
20 …iceRealTimeVoiceLua2-mobile 0x0000000102f5e114 lj_BC_JFUNCV + 44
21 …iceRealTimeVoiceLua2-mobile 0x0000000102f71354 lua_pcall + 164
22 …iceRealTimeVoiceLua2-mobile 0x0000000102dda4b4 cocos2d::LuaStack::executeFunction+ 107700 (int) + 172
23 …iceRealTimeVoiceLua2-mobile 0x0000000102dda5ac cocos2d::LuaStack::executeFunctionByHandler+ 107948 (int, int) + 76
24 …iceRealTimeVoiceLua2-mobile 0x0000000102dd81f0 cocos2d::LuaEngine::handleEvenCustom+ 98800 (void*) + 124
25 …iceRealTimeVoiceLua2-mobile 0x0000000102e2f154 std::__1::__function::__func<cocos2d::LuaEventListenerCustom::create(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&)::_1, std::__1::allocator<cocos2d::LuaEventListenerCustom::create(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::_1>, void (cocos2d::EventCustom*)>::operator()+ 454996 (cocos2d::EventCustom*&&) + 48
26 …iceRealTimeVoiceLua2-mobile 0x0000000103275960 std::__1::__function::__func<cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::_0, std::__1::allocator<cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::_0>, void (cocos2d::Event*)>::operator()+ 4938080 (cocos2d::Event*&&) + 48
27 …iceRealTimeVoiceLua2-mobile 0x000000010327cfe8 std::__1::__function::__func<cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::_2, std::__1::allocator<cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::_2>, bool (cocos2d::EventListener*)>::operator()+ 4968424 (cocos2d::EventListener*&&) + 72
28 …iceRealTimeVoiceLua2-mobile 0x0000000103278b30 cocos2d::EventDispatcher::dispatchEventToListeners(cocos2d::EventDispatcher::EventListenerVector*, std::__1::function<bool + 4950832 (cocos2d::EventListener*)> const&) + 356
29 …iceRealTimeVoiceLua2-mobile 0x0000000103278f68 cocos2d::EventDispatcher::dispatchEvent+ 4951912 (cocos2d::Event*) + 188
30 …iceRealTimeVoiceLua2-mobile 0x0000000103279774 cocos2d::EventDispatcher::dispatchCustomEvent+ 4953972 (std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void*) + 48
31 …iceRealTimeVoiceLua2-mobile 0x0000000102dc55fc AppDelegate::applicationWillEnterForeground() + 22012 (AppDelegate.cpp:163)
lua代码如下:local listenerForeGround=cc.EventListenerCustom:create(“APP_ENTER_FOREGROUND_EVENT”,function ()
print(“切换到前台”)
–cc.SimpleAudioEngine:getInstance():resumeMusic()
–cc.SimpleAudioEngine:getInstance():resumeAllEffects()
if device.platform == “ios” then
cc.SimpleAudioEngine:destroyInstance()
cc.SimpleAudioEngine:getInstance()
package.loaded[“cocos.framework.audio”] = nil
local audio = require(“cocos.framework.audio”)
cc.SimpleAudioEngine:getInstance():playMusic(“backMusic.mp3”, true)
end
CloudVoiceRealTimeVoiceManager.resume()
end)
customEventDispatch:addEventListenerWithFixedPriority(listenerForeGround, 1)

cocos 3.17 lua的cc.SimpleAudioEngine:destroyInstance()在ios崩溃

cc.SimpleAudioEngine:destroyInstance()
cc.SimpleAudioEngine:getInstance()
package.loaded[“cocos.framework.audio”] = nil
local audio = require(“cocos.framework.audio”)
cc.SimpleAudioEngine:getInstance():playMusic(“backMusic.mp3”, true)

这些代码的作用是什么?
为什么先destroyInstance再getInstance ,然后reload了cocos 已经弃用的audio模块?

在 AppDelegate里面宏打开了嘛
不需要你自己监听前后台事件然后操作Sample Audio的

确实不需要自己监听前后台事件然后操作Sample Audio的。但是客户反映3.13引擎有bug,前后台切换之后,ios上背景音乐不播放了,才写出这种代码。

直接调用sampleAudio有resume和pause的