unity打包ios真机测试应用切换后背景音乐的消失问题

初始打开关闭背景音乐添加代码:
unity打包好ios,导入xcode打开找到main.mm文件添加代码

	//添加头文件
	#include <AVFoundation/AVFoundation.h>
	//添加代码片段
 	NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
    [[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

添加相关在这里插入图片描述

unity打包后切入切出的时候背景音乐的处理在xcode找到UnityAppController.mm添加代码

	//添加头文件
	#include <AVFoundation/AVFoundation.h>
	//添加代码片段
 	NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategorySoloAmbient  error:&setCategoryErr];
    [[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

在这里插入图片描述
AVAudioSession 类的实例及类型

纪录一下,更新于2020.05.11。

猜你喜欢

转载自blog.csdn.net/weixin_44431724/article/details/105291807
今日推荐