iOS App在后台时接收到极光推送接收不到消息消息时,怎么去语音播报

iOS App在后台时接收到推送消息时,怎么去语音播报? - 开源中国社区
当前访客身份:游客 [
当前位置:
App在后台时接收到推送消息时,怎么去语音播报?
共有1个答案
<span class="a_vote_num" id="a_vote_num_
后台语音播报:
1.推送唤醒(程序在收到推送时可以在后台运行代码)
2.执行代码
1.启用推送唤醒
和上面的后台获取类似,更改Info.plist,在UIBackgroundModes下加入remote-notification即可开启,当然同样的更简单直接的办法是使用Capabilities。
2.更改推送的payload
在iOS7中,如果想要使用推送来唤醒应用运行代码的话,需要在payload中加入content-available,并设置为1。
& {"aps":{"content-available":1,"alert":"今天是个好天气"}}
"content-available":1&
& "alert":""&
& "badge":1 &
app右上角数字
“sound”:”default” &
&& & content-available: 1
&& & alert: {...}
3.实现推送唤醒代码并通知系统
最后在appDelegate中实现-application:didReceiveRemoteNotification:fetchCompletionHandle:。这部分内容和上面的后台获取部分完全一样,在此不再重复。
//接收到推送消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
& & NSLog(@"remote: %@", userInfo);
& & //回调
& & completionHandler(UIBackgroundFetchResultNewData);
& & //语音播报
& & AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:userInfo[@"aps"][@"alert"]];
& & AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
& & [synth speakUtterance:utterance];
更多开发者职位上
有什么技术问题吗?
tylerli...的其它问题
类似的话题IOS 本地推送消息以及进入后台继续推送
IOS 本地推送消息以及进入后台继续推送
首先编写本地推送的代码
UILocalNotification *notification = [[UILocalNotification alloc] init];
&&&&&&& notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:10];
&&&&&&& notification.timeZone=[NSTimeZone defaultTimeZone];
&&&&&&& notification.applicationIconBadgeNumber = 1; //设置右上角小圆圈数字为1
&&&&&&& notification.soundName= UILocalNotificationDefaultSoundN
&&&&&&& notification.alertBody = @“推送测试”;
&&&&&&& [[UIApplication sharedApplication]& scheduleLocalNotification:notification];
当按下Home健,程序开始进入后台,那么如果还要接受的话,需要在AppDelegate中加入如下代码。
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
&&&&&&& NSLog(@" application Recieved Notification %@",notif);
&&& app.applicationIconBadgeNumber = 0;
那么即使设备在锁定状态下,仍然能够显示本地推送。
发表评论:
TA的最新馆藏

我要回帖

更多关于 android接收推送消息 的文章

 

随机推荐