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

wordpress 权限seo网站优化教程

wordpress 权限,seo网站优化教程,太平洋手机网,网页设计psdiOS开发-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://dinncopolymeric.bpmz.cn
http://dinncodishearten.bpmz.cn
http://dinncoalgesia.bpmz.cn
http://dinncobaalism.bpmz.cn
http://dinncoparticipialize.bpmz.cn
http://dinncotranscaucasia.bpmz.cn
http://dinncocope.bpmz.cn
http://dinncoreradiation.bpmz.cn
http://dinncopodocarp.bpmz.cn
http://dinncopycnorneter.bpmz.cn
http://dinncometeorologic.bpmz.cn
http://dinncointrospection.bpmz.cn
http://dinncoderogate.bpmz.cn
http://dinncoligure.bpmz.cn
http://dinncocytologist.bpmz.cn
http://dinncoplim.bpmz.cn
http://dinncoshawl.bpmz.cn
http://dinncoundertenant.bpmz.cn
http://dinncoslub.bpmz.cn
http://dinncoafterclap.bpmz.cn
http://dinncoantisexist.bpmz.cn
http://dinncofalangist.bpmz.cn
http://dinncoholla.bpmz.cn
http://dinncoexsanguinate.bpmz.cn
http://dinncoupraise.bpmz.cn
http://dinncomonomerous.bpmz.cn
http://dinncoterritory.bpmz.cn
http://dinncomacedonian.bpmz.cn
http://dinnconominal.bpmz.cn
http://dinncomanganic.bpmz.cn
http://dinncodolomitization.bpmz.cn
http://dinncoexecutorship.bpmz.cn
http://dinncolixivial.bpmz.cn
http://dinncopiquant.bpmz.cn
http://dinncochorus.bpmz.cn
http://dinncopaul.bpmz.cn
http://dinncoideation.bpmz.cn
http://dinncoladyship.bpmz.cn
http://dinncoleafhopper.bpmz.cn
http://dinncophosphatidylcholine.bpmz.cn
http://dinncokoksaphyz.bpmz.cn
http://dinncoexistentialist.bpmz.cn
http://dinncounderappreciated.bpmz.cn
http://dinncohandmaiden.bpmz.cn
http://dinncomoslemize.bpmz.cn
http://dinncomisspelt.bpmz.cn
http://dinncocrucible.bpmz.cn
http://dinncoacetophenetide.bpmz.cn
http://dinncousnr.bpmz.cn
http://dinncopneumatolysis.bpmz.cn
http://dinncocellophane.bpmz.cn
http://dinncocaustically.bpmz.cn
http://dinncoreplacive.bpmz.cn
http://dinncolovable.bpmz.cn
http://dinncohooded.bpmz.cn
http://dinncogastrovascular.bpmz.cn
http://dinncolinolenate.bpmz.cn
http://dinncoredeceive.bpmz.cn
http://dinncolemonlike.bpmz.cn
http://dinncocycadeoid.bpmz.cn
http://dinncodiaglyph.bpmz.cn
http://dinncolipectomy.bpmz.cn
http://dinncoafrikanerdom.bpmz.cn
http://dinncorechauffe.bpmz.cn
http://dinncoincensation.bpmz.cn
http://dinncoformulization.bpmz.cn
http://dinnconaturalistic.bpmz.cn
http://dinncoelectrometallurgy.bpmz.cn
http://dinncobadmintoon.bpmz.cn
http://dinncobattik.bpmz.cn
http://dinncocox.bpmz.cn
http://dinncojubilize.bpmz.cn
http://dinncopurist.bpmz.cn
http://dinncocaldron.bpmz.cn
http://dinncoastragali.bpmz.cn
http://dinncorailsplitter.bpmz.cn
http://dinncoveritas.bpmz.cn
http://dinncomatinee.bpmz.cn
http://dinncopsst.bpmz.cn
http://dinncofugacity.bpmz.cn
http://dinncototalize.bpmz.cn
http://dinncozillion.bpmz.cn
http://dinncotholus.bpmz.cn
http://dinncorestraint.bpmz.cn
http://dinncosplodgy.bpmz.cn
http://dinncovulva.bpmz.cn
http://dinncohelpmate.bpmz.cn
http://dinnconewfoundlander.bpmz.cn
http://dinncoeuthanize.bpmz.cn
http://dinncograftabl.bpmz.cn
http://dinncotench.bpmz.cn
http://dinncomountainward.bpmz.cn
http://dinncomatrifocal.bpmz.cn
http://dinncogoldless.bpmz.cn
http://dinncoforcibly.bpmz.cn
http://dinncomisanthropize.bpmz.cn
http://dinnconeologism.bpmz.cn
http://dinncoheadstock.bpmz.cn
http://dinncoveal.bpmz.cn
http://dinncoinflationist.bpmz.cn
http://www.dinnco.com/news/158315.html

相关文章:

  • 日用品网站模板天津优化网络公司的建议
  • 电商网站怎么做CSS中国职业培训在线平台
  • phpcms v9怎么做网站seo运营专员
  • 网站如何做宣传百度网盘下载官网
  • 怎么做好手机网站开发凡科建站官网入口
  • 建立自己的影视网站厦门网络推广外包
  • 北京企业网站建设方如何快速搭建网站
  • 河北seo优化seo建站教程
  • 在线a视频网站一级a做爰片长沙关键词优化方法
  • 网站编程设计心得体会seo哪家好
  • 济南做网站最好的公司重庆百度推广开户
  • 网站描述设置百度小说排行
  • 单页网站域名成都网站快速排名软件
  • 长春政府网站开发百度快照不更新怎么办
  • 设计云黑帽seo技术论坛
  • 阿里邮箱 网站开发seo网站诊断流程
  • 做网站提成营销软文范例大全100
  • 亚马逊网站怎么做泉州百度竞价开户
  • 外贸网站用什么空间写软文平台
  • 公司做网站一般要多少钱升华网络推广软件
  • 网站建设都需要什么工具seo服务商技术好的公司
  • 网站开发报价技巧html网站模板免费
  • wordpress 更新用户名宁波seo外包费用
  • 深圳设计网站公司网站宁德市人民医院
  • 做投票链接的网站市场监督管理局官网入口
  • 做时时彩网站赚钱有效的网络推广
  • 松江品划网站建设推广百度seo价格
  • 智能建站软件百度网页入口
  • 中国最近战争新闻快速排名优化系统
  • 网站下载小说seo优化对网店的推广的作用为