132 lines
3.8 KiB
Objective-C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// VideoTalkManager.m
// VoIPTest
//
// Created by Tg W on 17/2/21.
// Copyright © 2017年 oopsr. All rights reserved.
//
#import "VideoTalkManager.h"
#import <PushKit/PushKit.h>
#import "RingCall.h"
#import "AppDelegate.h"
#import "Pub.h"
#import "HttpManager.h"
/**************注意事项******
1、证书制作是否完成
2、APP bundle identity是否替换成自己的
3、测试推送时确保推送的设备token跟上传的设备token一致
*************/
@interface VideoTalkManager ()<PKPushRegistryDelegate>{
NSString *token;
AppDelegate *app;
}
@property (nonatomic,strong)id<VideoCallbackDelegate>mydelegate;
@end
@implementation VideoTalkManager
static VideoTalkManager *instance = nil;
+ (VideoTalkManager *)sharedClinet {
if (instance == nil) {
instance = [[super allocWithZone:NULL] init];
}
return instance;
}
-(void)initWithSever {
NSLog(@"initWithSever");
//voip delegate
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
//ios10注册本地通知
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
[[RingCall sharedMCCall] regsionPush];
}
}
- (void)setDelegate:(id<VideoCallbackDelegate>)delegate {
self.mydelegate = delegate;
}
#pragma mark -pushkitDelegate
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
NSLog(@"didUpdatePushCredentials");
if([credentials.token length] == 0) {
NSLog(@"voip token NULL");
return;
}
//应用启动获取token并上传服务器
NSLog(@"didUpdatePushCredentials%@",credentials.token);
token = [[[[credentials.token description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
//token上传服务器
//[self uploadToken];
[Pub getApp].sysinfo.pushkitToken = token;
NSLog(@"didUpdatePushCredentials%@",[Pub getApp].sysinfo.pushkitToken);
// [HttpManager postPushkitToken:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token PushkitToken:token HttpResultHandler:^(NSDictionary *json) {
// NSLog(@"上传token成功");
// }];
//[app uploadTokenWithToken:token];
//app.pushkitToken = [NSString stringWithFormat:@"%@", token];
//NSLog(@"get pushkit token:%@", token);
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type{
NSLog(@"didReceiveIncomingPushWithPayload");
#if 1
BOOL isCalling = false;
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive: {
//isCalling = false;
//[app onCallRing:@"jjfj"];
isCalling = true;
}
break;
case UIApplicationStateInactive: {
//isCalling = false;
isCalling = true;
}
break;
case UIApplicationStateBackground: {
isCalling = true;
}
break;
default:
isCalling = true;
break;
}
NSDictionary *dic = [payload.dictionaryPayload objectForKey:@"aps"];
NSString *info = [dic objectForKey:@"alert"];
if (isCalling){
//本地通知,实现响铃效果
//NSLog(@"%@", [dic objectForKey:@"alert"]);
[self.mydelegate onCallRing:info];
}
else {
[[RingCall sharedMCCall] onCallRing:info];
}
#endif
}
@end