Gruveo SDK for iOS
iOS的Gruveo SDK和一个示例项目。
Pod安装
要将Gruveo SDK for iOS添加到您的应用程序中,您需要CocoaPods,这是一个Objective-C的依赖项管理器。您可以使用以下命令安装CocoaPods:
$ gem install cocoapods
Podfile
要在CocoaPods中使用Podfile将Gruveo SDK集成到您的Xcode项目中,请在您的Podfile中添加GruveoSDK
pod
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TargetName' do
pod 'GruveoSDK'
end
然后,运行以下命令:
$ pod install
应用程序设置和使用
- 将
NSCameraUsageDescription
和NSMicrophoneUsageDescription
添加到您的应用程序的Info.plist中 - 在“Target -> Build Settings -> Enable Bitcode”中将“Enable Bitcode”设置为NO
- 在“Capabilities -> Background Modes”下检查“Audio, AirPlay, and Picture in Picture”复选框
- 将
GruveoSDK
导入到AppDelegate
和您的ViewController
类中
@import GruveoSDK;
- 在应用程序启动后注册您的客户端ID
[GruveoCallManager setClientId:@"demo”]
- 在
viewDidLoad
函数中为GruveoCallManager
设置代理
[GruveoCallManager setDelegate:self]
- 实现 Gruveo 通话界面的创建
[GruveoCallManager callCode:@"hello" videoCall:YES onViewController:self callCreationCompletion:^(CallInitError creationError) {
if (creationError != CallInitErrorNone) {
// Show error here
}
}];
- 实现令牌签名委托功能。 警告:以下示例实现使用Gruveo提供的签名端点,并且仅适用于
demo
客户端ID。
- (void)requestToSignApiAuthToken:(NSString *)token {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api-demo.gruveo.com/signer"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[token dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if ([data isKindOfClass:[NSData class]]) {
NSString *signedToken = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[GruveoCallManager authorize:signedToken];
} else {
[GruveoCallManager authorize:nil];
}
}] resume];
}
- 实现其他有用的委托功能。
- (void)callEstablished {}
- (void)callEnd:(GruveoCallEndReason)reason {}
- (void)recordingStateChanged {}
- 构建并运行您的应用程序。