ios不点击通知栏如何触发通知回调

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios不点击通知栏如何触发通知回调相关的知识,希望对你有一定的参考价值。

参考技术A ios不点击通知栏的话触发他那个通知回调的话你可以在设置里面调节的。 参考技术B 不点击通知栏处罚通知,回调的话应该是里面有一个下拉菜单,点击一下。 参考技术C iOS如果不点击,通知栏的话,你就只能下拉到上面这句我左上角的。 参考技术D IOS那是有说明书的,你可以把你的问题输入看看,能不能找到相应的一些操作的知道。

如何在 iOS 中触发通知时打开警报视图?

【中文标题】如何在 iOS 中触发通知时打开警报视图?【英文标题】:How to open alert view when notification fires in iOS? 【发布时间】:2013-10-24 06:25:49 【问题描述】:

我制作了一个触发本地通知的示例应用程序。

当通知触发时,它总是在设备的通知区域显示横幅,我已在图像中显示。

但我想要警报而不是这个,并希望根据从该警报中选择的选项执行操作。

触发本地通知的代码如下。

-(IBAction)setNotification:(id)sender

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)

    return;


localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Get the year, month, day from the date
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSTimeZoneCalendarUnit|NSSecondCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:[NSDate date]];

// Set the second to be zero
components.minute = components.minute + 1;
components.second = 0;

// Create the date
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
NSLog(@"Fire Date :: %@",date);
localNotif.fireDate = date;

localNotif.alertBody = [NSString stringWithFormat:@"First Alarm"];


localNotif.alertAction =@"Ok";

localNotif.soundName=@"Alarm_1.mp3";

localNotif.applicationIconBadgeNumber = 1;


localNotif.alertAction = @"Application name";
localNotif.HasAction = true;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

如果有任何错误,请任何人告诉我。

提前致谢。

【问题讨论】:

所以等等。您想通过在主屏幕中显示警报视图来对通知采取措施? 是的,我想采取行动。 您希望通知看起来像 UIAlertView? 是的,我希望它作为来自以下网址的图像。 developer.apple.com/library/ios/documentation/… 这样可以吗? 【参考方案1】:

这是一个快速而简短的答案。你不能这样做。 Apple 的文档仅说明 didReceiveLocalNotification。显示通知的方式不取决于开发人员。用户将使用设置选择他希望如何查看通知。

在您的情况下,只需通过在用户点击通知时实现委托回调来连接逻辑。

【讨论】:

【参考方案2】:

在设置 -> 通知中心 -> 你的应用 -> 警报中更改通知类型:

最初来自奎因“爱斯基摩人!”,quoted by IBG:

“这取决于你的意思。你可以控制 根据您设置 UILocalNotification 的方式显示通知 属性(例如 alertBody、soundName 等)。然而,如果 您在询问解释这些属性的方式 (用户可以在“设置”>“通知”中自定义的东西),那些 是用户偏好,不通过任何 API 公开。”

【讨论】:

是的,这是一种方法,但我不想要它手动我想要它以编程方式,因为我们在安装应用程序时默认需要它,你知道有什么方法可以摆脱是吗? @JayeshSojitra,你不能以编程方式做到这一点。请参阅我的更新答案。【参考方案3】:

您可以通过这种方式获取您的通知:

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

编写此代码以从 userInfo 中获取数据:

[[userInfo objectForKey:@"aps"] objectForKey:@"price"]];

使用 userInfo Dict 获取通知值,然后您可以将该数据用于警报。

【讨论】:

这是本地通知而不是远程通知。

以上是关于ios不点击通知栏如何触发通知回调的主要内容,如果未能解决你的问题,请参考以下文章

iOS 本地通知 - 在后台时回调

PushWoosh 通知回调未触发

iOS 9:如何检测用户何时对推送通知请求说“不允许”? [复制]

iOS 10 推送通知点击处理程序

点击通知时Activity中的触发方法

当应用程序在后台 iOS 11 中时,UNNotification 本地通知用户点击不会触发委托