132 lines
3.8 KiB
Mathematica
Raw Normal View History

//
// 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
2APP bundle identity
3tokentoken
*************/
@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