当前位置: 首页 > news >正文

网站设计建设定制郑州今日重大新闻

网站设计建设定制,郑州今日重大新闻,建立网站需要做什么,前端开发就是做网站吗iOS开发-NotificationServiceExtension实现实时音视频呼叫通知响铃与震动 在之前的开发中,遇到了实时音视频呼叫通知,当App未打开或者App在后台时候,需要通知到用户,用户点击通知栏后是否接入实时音视频的视频或者音频通话。 在…

iOS开发-NotificationServiceExtension实现实时音视频呼叫通知响铃与震动

在之前的开发中,遇到了实时音视频呼叫通知,当App未打开或者App在后台时候,需要通知到用户,用户点击通知栏后是否接入实时音视频的视频或者音频通话。

在iOS需要为工程新建Target:NotificationServiceExtension

一、主工程配置

需要在主工程中开启推送功能,配置证书。

在这里插入图片描述

二、新建NotificationServiceExtension的target

新建NotificationServiceExtension的target

在这里插入图片描述

三、实现NotificationService

在NotificationService的方法

// 主要代码
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler- (void)serviceExtensionTimeWillExpire;

在didReceiveNotificationRequest实现呼叫响铃及震动效果。

// 通过通知的Sound设置为voip_call.caf,这里播放一段空白音频,音频结束后结束震动NSString *path = [[NSBundle mainBundle] pathForResource:@"blank_call.mp3" ofType:nil];AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallback, NULL);AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, soundCompleteCallback, NULL);

完整代码如下

#import "NotificationService.h"
#import <AVFoundation/AVFAudio.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>@interface NotificationService ()
{SystemSoundID soundID;
}@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;@property (nonatomic, strong) NSMutableArray *requests;@end@implementation NotificationService- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {self.contentHandler = contentHandler;self.bestAttemptContent = [request.content mutableCopy];BOOL playVoice = NO;NSString *chatPushVo = [self.bestAttemptContent.userInfo objectForKey:@"chatPushVo"];if (chatPushVo && [chatPushVo isKindOfClass:[NSString class]] && chatPushVo > 0) {NSDictionary *dict = [self dictionaryWithJsonString:chatPushVo];if (dict && [dict isKindOfClass:[NSDictionary class]]) {NSString *type = [NSString stringWithFormat:@"%@", [dict objectForKey:@"type"]];// type : 0 呼叫if ([@"0" isEqualToString:type]) {playVoice = YES;// 通过通知的Sound设置为voip_call.caf,这里播放一段空白音频,音频结束后结束震动NSString *path = [[NSBundle mainBundle] pathForResource:@"blank_call.mp3" ofType:nil];AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallback, NULL);AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, soundCompleteCallback, NULL);[self playVoiceWithContent:self.bestAttemptContent.userInfo];}}}if (playVoice == NO) {self.contentHandler(self.bestAttemptContent);}
}- (void)playVoiceWithContent:(NSDictionary *)userInfo {//  iOS 10之前前台没有通知栏// 此处调用之前的语音播报的内容[self playRegisterNotifications:userInfo];
}- (void)playRegisterNotifications:(NSDictionary *)userInfo {[self registerNotifications:userInfo];
}- (void)registerNotifications:(NSDictionary *)userInfo {[self startShakeSound];
}/// 开始响铃
- (void)startShakeSound {// 声音AudioServicesPlaySystemSound(soundID);// 震动AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);self.contentHandler(self.bestAttemptContent);
}/// 结束响铃
- (void)stopShakeSound {AudioServicesDisposeSystemSoundID(soundID);AudioServicesRemoveSystemSoundCompletion(soundID);
}//AudioServicesAddSystemSoundCompletion的回调函数
void soundCompleteCallback(SystemSoundID sound,void * clientData) {if (sound == kSystemSoundID_Vibrate) {AudioServicesPlayAlertSound(sound);//重复响铃震动} else {// 移除AudioServicesDisposeSystemSoundID(sound);AudioServicesRemoveSystemSoundCompletion(sound);AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate);AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);}
}- (void)serviceExtensionTimeWillExpire {// Called just before the extension will be terminated by the system.// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.self.contentHandler(self.bestAttemptContent);
}/**json转成NSDictionary@param jsonString json字符串@return NSDictionary*/
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {if (jsonString == nil) {return nil;}NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];NSError *err;NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];if(err) {return nil;}return dic;
}@end

四、使用推送

我这里使用的极光推送,注意需要设置推送的mutable-content=1字段。

在这里插入图片描述

五、点击通知后处理是否通实时音视频视频通话

在收到通知后,用户点击点击通知后处理是否通实时音视频视频通话逻辑。

在AppDelegate的方法

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

增加didReceiveRemoteNotification

// 获取启动时收到的APNNSDictionary *userInfo = [[DFPushManager shareInstance] launchOptionsRemoteNotification:launchOptions];if (userInfo) {[self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) {}];}

当收到通知后,在didReceiveRemoteNotification中处理是否接通实时音视频的视频通话的逻辑

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {DFDebugLogger(@"didReceiveRemoteNotification");[[SDPushManager shareInstance] handleRemoteNotification:application userInfo:userInfo completion:nil];NSLog(@"收到通知:%@", userInfo);[[SDPushManager shareInstance] setBadgeNumberMax:nil];if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {// 登录后调用check__weak typeof(self) weakSelf = self;if (userInfo && [userInfo isKindOfClass:[NSDictionary class]]) {NSString *chatPushVo = [userInfo objectForKey:@"chatPushVo"];if (chatPushVo && [chatPushVo isKindOfClass:[NSString class]] && appPushVo.length > 0) {NSDictionary *dict = [DFJsonUtil dictionaryWithJsonString: chatPushVo];if (dict && [dict isKindOfClass:[NSDictionary class]]) {NSString *type = [NSString stringWithFormat:@"%@", [dict objectForKey:@"type"]];// type : 0 呼叫/// 0/用户呼叫// 打开接听页面,进行接听}}}}completionHandler(UIBackgroundFetchResultNewData);
}

六、小结

iOS开发-NotificationServiceExtension实现实时音视频呼叫通知与语音播报

在之前的开发中,遇到了实时音视频呼叫通知,当App未打开或者App在后台时候,需要通知到用户,用户点击通知栏后是否接入实时音视频的视频或者音频通话。

学习记录,每天不停进步。

http://www.zhongyajixie.com/news/15427.html

相关文章:

  • 做特卖网站有哪些优化推广网站怎么做
  • 微信网页手机登录入口官网广东seo推广费用
  • 黄岩做网站外包推广服务
  • 做外贸去哪个网站找客户seo群发软件
  • 集宁有做蒙古黑石材网站的嘛线上推广方式
  • 网站的图片怎么制作绍兴seo排名收费
  • 做网站电话网络推广工作怎么样
  • 国外b站推广2024mmmseo百度快速排名软件
  • 有教做路桥质检资料的网站吗网站关键词
  • 双语网站模板下载友情链接收录
  • 石家庄商城网站制作百度极简网址
  • 云南房产网站建设如何制作自己的网址
  • nas 可以做网站吗网络舆情监测系统软件
  • ai制作海报seo如何优化关键词上首页
  • 百度做网站推广上海网站营销seo电话
  • 长春世邦做网站丁的老头seo博客
  • 免费网站推荐货源免费网站推广网站在线
  • wordpress灯箱效果seo搜索推广费用多少
  • 怎么做.com的网站东莞谷歌推广公司
  • 做视频网站的公司有哪些国外网站设计
  • 表格做的网站影响收录seo就业前景
  • 北京市优化网站贵港seo关键词整站优化
  • 网站需要怎么做开发app需要多少资金
  • 网站可以做外部链接吗app 推广
  • 什么叫搭建平台大型seo公司
  • 微信网站开发企业宁波核心关键词seo收费
  • 加强公司内部网站建设黄山网络推广公司
  • 百度商桥置入网站如何优化seo关键词
  • 福建网络seo关键词优化教程衡阳seo优化
  • 网站结构是体现的开发小程序