我在App Delegate中设置了本地通知使用此方法:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"Watch the Latest Episode of CCA-TV"];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序然后退出它时,我收到一条错误消息:
2014-06-07 11:14:16.663 CCA-TV [735:149070] 试图安排本地通知 {开火日期= 2014年6月7日星期六太平洋夏令时间11:14:21,时区= America/Los_Angeles (PDT)偏移-25200(日光),重复间隔= 0,重复计数= UILocalNotificationInfiniteRepeatCount,下一个开火日期= 2014年6月7日星期六太平洋夏令时间11:14:21,用户信息=(null)} 带警报但尚未收到用户显示警报的许可
如何获得显示警报的必要权限?
我想知道如何设置本地通知,以便在我设置时,我的应用程序生成带有自定义消息的通知/警报...
当Apple的官方iOS消息应用程序处于打开状态并位于前台时,来自其他联系人的新消息会触发库存本机iOS通知警报横幅.见下图.
这在App Store的第三方应用程序中是否可行?应用程序处于打开状态且位于前台时,应用程序的本地和/或推送通知?
在测试我的应用时,会收到通知,但不会显示iOS警报用户界面.
但是,这种行为是出现在苹果的官方消息应用程序:

在本地和远程通知编程指南说:
当操作系统提供本地通知或远程通知且目标应用程序未在前台运行时,它可以通过警报,图标标记号或声音向用户显示通知.
如果应用程序在传递通知时在前台运行,则应用程序委托会收到本地或远程通知.
所以是的,我们可以在前台接收通知数据.但我认为无法呈现本机iOS通知警报UI.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// I know we still receive the notification `userInfo` payload in the foreground.
// This question is about displaying the stock iOS notification alert UI.
// Yes, one *could* use a 3rd party toast alert framework.
[self use3rdPartyToastAlertFrameworkFromGithub]
}
Run Code Online (Sandbox Code Playgroud)
然后消息是否使用私有API在前台显示警报?
对于这个问题的目的,请不要提出任何第三方"敬酒",弹出警报在github上或者等我只是有兴趣,如果这可以用做库存,提供原生iOS本地或推送通知提醒用户界面,而你应用程序是开放的,在前台 …
uikit toast apple-push-notifications ios uilocalnotification
我正在开发基于本地通知的iPhone闹钟应用程序.
删除警报时,相关的本地通知应取消.但是,如何确定要取消本地通知数组中的哪个对象呢?
我知道[[UIApplication sharedApplication] cancelLocalNotification:notification]方法,但我怎么能得到这个'通知'取消它?
有没有办法知道应用程序是否通过本地通知变为活动状态?
我知道有一种方法来测试,如果应用程序被启动从本地通知提醒; 但如果只是坐在那里的背景,并收到通知?
当应用程序变为活动状态时,我需要运行不同的代码:
有办法吗?
我试图在iOS 8中检测应用程序的本地通知设置
对UIUserNotificationSettings,它返回我7我已经把所有的徽章,声音和提醒.
在设置中,我关闭"允许通知",应用程序仍然返回我的UIUserNotificationSettings(徽章,声音和警报).有没有办法检测"允许Notification"开/关?
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
NSLog(@"---notificationSettings.types %d" , notificationSettings.types );
if(notificationSettings.types!=7){
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Please turn on Notification"
message:@"Go to Settings > Notifications > App.\n Switch on Sound, Badge & Alert"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}
}
Run Code Online (Sandbox Code Playgroud) 这可能是一个问题,但我想知道要使用什么而不是UILocalNotificationiOS10.我正在开发一个部署目标为iOS8的应用程序,所以可以使用UILocalNotification吗?
从iOS 5开始,有两种通知样式:横幅和警报("旧"样式).用户可以在设置中设置要为每个应用程序使用的样式.但是,现在默认似乎是通知显示横幅样式.
我正在使用本地通知来提醒"现在"发生的事件.一个横幅在它出现后不久就消失了(并且它不够明显,人们可以点击它),所以对于这些通知,需要将警报样式通知保留在屏幕上直到用户决定一个动作(忽略或去到应用程序).
有没有办法通过代码或例如Info.plist条目告诉iOS默认情况下应该使用警报样式通知(只要用户没有配置其他东西)?
更新:缺乏信息/文件是不足以让我解决这个问题.我想要一个像权威人士的论坛/博客文章(Apple员工或Erica Sadun的人)说这是不可能的,或者如果有可能那么我想要解决方案.像"要求用户更改设置"这样的解决方法也不够好.
显然,ios10现在可以实现这一点:
optional func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
Run Code Online (Sandbox Code Playgroud)
这个答案基本上说明了做这件事所需的工具:
当您的应用程序处于打开状态且位于前台时显示库存iOS通知横幅?
我只是不太了解如何将它们放在一起.
我不知道这有多重要,但我无法保留可选的func,xcode要我将其切换为私有.
我正试图展示徽章,文档提供
static var badge: UNNotificationPresentationOptions { get }
Run Code Online (Sandbox Code Playgroud)
这里很少丢失.
然后我假设我想要排除某个视图控制器获取这些徽章并且我没有使用导航控制器这个代码我发现它会起作用吗?:var窗口:UIWindow?
if let viewControllers = window?.rootViewController?.childViewControllers {
for viewController in viewControllers {
if viewController.isKindOfClass(MyViewControllerClass) {
print("Found it!!!")
}
}
}
Run Code Online (Sandbox Code Playgroud) ios uilocalnotification swift swift3 unusernotificationcenter
我的应用程序允许用户将来设置一些提醒.当应用程序启动时,我想知道已经设置了什么提醒(通知).
我可以回读我已设置的通知或我需要存储在我的应用程序中的通知(例如核心数据或Plist)吗?
ios ×8
iphone ×3
ios8 ×2
objective-c ×2
swift ×2
background ×1
cocoa-touch ×1
ios5 ×1
swift3 ×1
toast ×1
uikit ×1