初始化
在使用 SDK 功能前,必须先进行初始化。
准备 App Key
你必须拥有正确的 App Key,才能进行初始化。
请联系项目管理人员获取 App Key。
初始化配置
获取 App Key, 并在程序启动时进行初始化。
方法定义
swift
class func initWith(appKey: String, config: KIMInitConfig)
Objective-C
+ (void)initWithAppKey:(NSString *)appKey config:(KIMInitConfig *)config
参数说明
参数 | 类型 | 说明 |
---|---|---|
appKey | String | 从企业管理后台获取到的 App Key |
config | KIMInitConfig | 初始化配置 |
KIMInitConfig
说明:
属性 | 类型 | 说明 |
---|---|---|
entryJsonUrl | URL? | 私有化服务部署后得到的服务入口地址。当服务为私有化部署时则需要设置该参数,否则无法访问服务。不传则默认使用公网服务。 |
allowUnsafeHttps | Bool | 是否允许不安全的https证书。默认为false,该属性为了兼容私网部署没有使用合法https证书的情况,考虑到网络安全性,一般不推荐修改为true。 |
amapKey | String | 高德地图apiKey。SDK内置地图服务默认使用高德地图,当使用内置地图服务时,需要把在高德开放平台注册得到apiKey设置到该属性。 |
rootPath | String? | 根目录路径。设置后SDK会把 rootPath 作为父目录,数据会存放到rootPath下的路径。rootPath 默认值为:NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last。 |
appDisplayName | String? | app 展示名称,用于内部页面文案展示,如群邀请页面文案。不传则使用Bundle.main.infoDictionary?["CFBundleDisplayName"]。 |
isV7 | Bool | 私有化服务版本是否为V7。默认由sdk打包配置决定。 |
subOrigins | [String]? | 多域名互通业务场景需要转换的域名列表。 |
application | UIApplication? | 应用上下文。 |
appLaunchOptions | [UIApplication.LaunchOptionsKey: Any]? | 应用启动参数。 |
isDebugMode | Bool | 是否为调试模式,开启后 websocket 支持代理, 默认为false。 |
代码示例
swift
// 配置 KIMKitConfig
let config = KIMInitConfig()
// 私有化环境设置,entryJSONUrl为请求入口地址,服务布署后可取到
config.entryJsonUrl = URL(string: "https://10.13.4.146")
// 初始化调用
KIM.initWith(appKey: "AK20231010GGXQGI", config: config)
Objective-C
// 配置 KIMKitConfig
KIMKitConfig *config = [[KIMInitConfig alloc] init];
// 私有化环境设置,entryJSONUrl为请求入口地址,服务布署后可取到
config.entryJsonUrl = [[NSURL alloc] initWithString:@"https://10.13.4.146"];
// 初始化调用
[KIM initWithAppKey:@"AK20231010GGXQGI" config:config];