voip推送

本文深入探讨了微信实现收款到账语音提醒的技术原理,重点讲解了VoIP推送通知的工作机制及其在即时通讯软件中的应用。文章对比了普通推送与VoIP推送的区别,并详细介绍了如何在iOS应用中配置和使用VoIP推送,包括证书设置、推送注册及消息解析等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近看了一篇文章,说的是微信实现收款到账语音提醒功能实现。原文章 文中提到了VoIP Push Notification,本文针对推送的种类以及如何利用推送唤醒 app 进行总结。
普通推送

远程推送和本地推送

区别网上资料太多了,简单说一下,比如今日头条,有什么大的新闻会在手机端接收到推送,这个就是远程推送,是把相关信息推送到苹果推送服务器-APNS。本地推送就是在本地设定一个时间,其实就是一个类似闹钟的功能,当到了设定的时间,就会收到一条推送,这个是和推送服务器没有关系的。

VoIP Push Notification

打视频或者语音电话的时候推送功能,一个典型的应用场景,A用户拨打B用户视频或者语音电话,A拨打,B铃声响起,此时A挂断,B铃声消失,就相当于控制对方手机一样。国外的语音视频电话都是采用voip push,比如whats app,line等语音视频通讯软件。

证书设置上的区别

在这里插入图片描述

Xcode 上的设置

勾选功能
在这里插入图片描述

引入开发包

在这里插入图片描述

注册VoIP 推送,该方法需要在初始化 app 的时候进行调用

-(void)registerVoipNotifications{

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

voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

UIUserNotificationType types = (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert);

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

[[UIApplication sharedApplication]registerUserNotificationSettings:notificationSettings];

}
获取token,用于发送到服务器端,服务器端发送推送消息时,会发送这个token到APNS服务器,APNS通过这个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);
    }
    对推送过来的消息进行解析,可以在推送的时候设置标记,下面的代码是获取到标志以后,根据标志命令调用不同的方法进行处理,进而实现功能,注意这里接收到消息定义时,如果传过来的命令是call就创建一个本地推送,提示某人正在呼叫你,如果传过来的命令为cancel,就取消命令

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

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

    if (theType == UIUserNotificationTypeNone)
    {
    UIUserNotificationSettings *userNotifySetting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:userNotifySetting];
    }

    NSDictionary * dic = payload.dictionaryPayload;

    NSLog(@“dic %@”,dic);

    if ([dic[@“cmd”] isEqualToString:@“call”]) {
    UILocalNotification *backgroudMsg = [[UILocalNotification alloc] init];
    backgroudMsg.alertBody= @“You receive a new call”;
    backgroudMsg.soundName = @“ring.caf”;
    backgroudMsg.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber] + 1;
    [[UIApplication sharedApplication] presentLocalNotificationNow:backgroudMsg];
    }else if(([dic[@“cmd”] isEqualToString:@“cancel”]){

    [[UIApplication sharedApplication] cancelAllLocalNotifications];

UILocalNotification * wei = [[UILocalNotification alloc] init];
wei.alertBody= [NSString stringWithFormat:@"%ld 个未接来电",[[UIApplication sharedApplication]applicationIconBadgeNumber]];
wei.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber];
[[UIApplication sharedApplication] presentLocalNotificationNow:wei];
}
}
原文:https://blog.csdn.net/jjblockAndmm/article/details/78879089

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值