iOS SDK开发说明
本文是为使用iOS SDK做一些通用的准备和说明,包括IDE和工程配置等。
一、支持平台
- SDK支持iOS 8.0以上系统
- 互动SDK最低支持iOS 9.0以上系统,不支持模拟器
二、开发环境
- Xcode 8或更高版本
- OS X 10.10或更高版本
三、Xcode工程设置
下面通过一个简单的iOS Application工程,说明如和在Xcode工程中配置SDK。
1、创建iOS 工程
新建一个 TestProject 的iOS工程
选择ios 单文档app 并点击Next按钮
填写工程名并 记录Bundle ID 并去开发者中心【设置iOS包名】 点击Next按钮选择项目存储位置,再点击Create按钮,即完成IOS工程创建
2、拷贝SDK文件
下载【微吼云IOS SDK】
将下载下来的文件夹拷贝至工程目录,然后拖动到Xcode中。目录结构如下图所示:
3、添加库和Framework
libc++.tbd
libbz2.1.0.tbd
libicucore.tbd
libz.tbd
libiconv.tbd
CoreTelephony.framework
MediaPlayer.framework
AVFoundation.framework
VideoToolbox.framework
AssetsLibrary.framework
OpenAL.framework
OpenGLES.framework
QuartzCore.framework
CoreMedia.framework
Security.framework
按下图四步找到添加位置
添加方式:点击第四步左下方 “+” 按钮 搜索上边库确定添加即可
VhallLiveBaseApi.framework VhallSignalingDynamic.framework WebRTC.framework 添加方式:点击第四步左下方 “+” 按钮 选择相应库确定添加即可
4、工程设置修改
- AppDelegate.m 文件名修改为AppDelegate.mm
- Build Setting 中 Enable Bitcode 设置为NO
如下图:
- 设置Info.plist中 App Transport Security Settings -> Allow Arbitrary Loads 设置为 YES
- 设置Info.pplist中 Privacy - Camera Usage Description 是否允许使用相机
- 设置Info.pplist中 Privacy - Microphone Usage Description 是否允许使用麦克风
如下图:
四、验证
下面在TestProject的代码中,调用SDK的接口,设置appID 获取SDK版本信息,以验证工程设置是否正确。
1、引用头文件
在AppDelegate.mm开头引用SDK的头文件:
#import "VHLiveBase.h"
2、添加调用代码
在application: didFinishLaunchingWithOptions:方法中添加代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[VHLiveBase registerApp:@"xxxxxxxxx"];//AppID:xxxxxxxxx
[VHLiveBase setThirdPartyUserId:@"xxxxxxxx"];//第三方账号id:xxxxxxxx
NSLog(@"SDK Version: %@",[VHLiveBase getSDKVersion]);
return YES;
}
3、编译运行
如果前面各个步骤都操作正确的话,TestProject工程应该可以顺利编译通过。在Debug模式下运行APP,Xcode的Console窗格会打印出SDK的版本信息。
具体步骤如下图:
至此,工程配置完成。
注册APP
[VHLiveBase registerApp:@"xxxxxxxxx"];//AppID:xxxxxxxxx
设置第三方ID
[VHLiveBase setThirdPartyUserId:@"xxxxxxxx"];//第三方账号id:xxxxxxxx
LOG输出
在 VHLiveBase 中可以设置 log的级别,具体代码如下:
[VHLiveBase setLogLevel:VHLogLevelDebug];
在 VHLiveBase 中可以设置 是否输出到控制台,具体代码如下:
[VHLiveBase printLogToConsole:YES];
打包上传 App Store 问题
打包上传 App Store 如果报 x86_64 或者 i386 的错误,请使用 liop 命令去掉 错误提示的 framework 的模拟器库。
使用 liop 命令 使用方法: 点击参考
1、打开终端
所有程序中找到它,点击打开或使用聚焦搜索(点按菜单栏右上角的搜索图标,或按下 Command-空格键),输入「终端」或「Terminal」,看到终端被选中了按下回车即可。
2、拆分多架构支持的静态库
比如 VhallLiveBaseApi.framework,
1)cd到库的文件夹cd /Users/xxxx/Desktop/VHallSDK
2)使用lifo -info 可以查看包含的架构 lipo -info VhallLiveBaseApi.framework/VhallLiveBaseApi
Architectures in the fat file: VhallLiveBaseApi are: i386 x86_64 armv7 armv7s arm64
3)移除x86_64, i386 模拟器库,上传 App Store 时会报错,用以下命令移除
lipo -remove x86_64 VhallLiveBaseApi.framework/VhallLiveBaseApi -o VhallLiveBaseApi.framework/VhallLiveBaseApi
lipo -remove i386 VhallLiveBaseApi.framework/VhallLiveBaseApi -o VhallLiveBaseApi.framework/VhallLiveBaseApi
4)再次查看lipo -info VhallLiveBaseApi.framework/VhallLiveBaseApi
Architectures in the fat file: VhallLiveBaseApi are: armv7 armv7s arm64
3、合并多个架构静态库
lipo -create VhallLiveBaseApi.framework/VhallLiveBaseApi.i386.a VhallLiveBaseApi.framework/VhallLiveBaseApi.arm.a -output VhallLiveBaseApi.framework/VhallLiveBaseApi.a