iOS Voip push部分笔记

Voip push与普通push区分开的部分

引入PushKit头文件 

#import <PushKit/PushKit.h>

遵守协议

<PKPushRegistryDelegate>

声明属性

@property(nonatomic,strong)PKPushRegistry *voipRegistry;

AppDelegate中:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

[self registerVoipNotifications];

returnYES;

}

注册Voip push

- (void)registerVoipNotifications{

PKPushRegistry *voipRegistry = [[PKPushRegistry alloc]initWithQueue:dispatch_get_main_queue()];

voipRegistry.delegate=self;

voipRegistry.desiredPushTypes= [NSSetsetWithObject:PKPushTypeVoIP];

UIUserNotificationType types = (UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert);

UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication]registerUserNotificationSettings:notificationSettings];

}

#pragma mark - PKPushRegistryDelegate

收到token回调

- (void)pushRegistry:(PKPushRegistry*)registry didUpdatePushCredentials:(PKPushCredentials*)credentials forType:(NSString*)type{

NSString*str = [NSString stringWithFormat:@"%@",credentials.token];

NSString*_tokenStr = [[[str stringByReplacingOccurrencesOfString:@"<"withString:@""]

stringByReplacingOccurrencesOfString:@">"withString:@""] stringByReplacingOccurrencesOfString:@" "withString:@""];

NSLog(@"device_token is %@", _tokenStr);

[YFRInfoToast showInfo:_tokenStr bgColor:[UIColor blackColor].CGColor inView:self.window vertical:0.7];//弹toast

}

收到Voip消息回调

- (void)pushRegistry:(PKPushRegistry*)registry didReceiveIncomingPushWithPayload:(PKPushPayload*)payload forType:(NSString*)type {

//此时进行voip注册

// write your voip related codes here

UIUserNotificationType theType = [UIApplication sharedApplication].currentUserNotificationSettings.types;

if(theType ==UIUserNotificationTypeNone){

UIUserNotificationSettings*userNotifySetting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];

[[UIApplication sharedApplication]registerUserNotificationSettings:userNotifySetting];

}

UILocalNotification *backgroudMsg = [[UILocalNotification alloc]init];

backgroudMsg.alertBody=@"You receive a new call";

[[UIApplication sharedApplication]presentLocalNotificationNow:backgroudMsg];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容