- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
presentLocalNotificationNow
和 scheduleLocalNotification
有什么区别。
因为以下两个函数都是在 1 秒后显示通知
-(void)showLocalNotification:(NSNotification *)notification {
NSString *msg = @"test message";
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *_localNotification = [[UILocalNotification alloc]init];
_localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
_localNotification.timeZone = [NSTimeZone defaultTimeZone];
_localNotification.alertBody = msg;
_localNotification.soundName = UILocalNotificationDefaultSoundName;
_localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber]+1;
[[UIApplication sharedApplication] scheduleLocalNotification:_localNotification];
// or
//[[UIApplication sharedApplication] presentLocalNotificationNow:_localNotification];
}
最佳答案
如果应用程序在后台运行,本地通知将不会发出警报或声音,因为它直接由应用程序接收。在这种情况下,您需要使用 presentLocalNotificationNow 显示通知。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState applicationState = application.applicationState;
if (applicationState == UIApplicationStateBackground) {
[application presentLocalNotificationNow:notification];
}
}
来自 Apple 文档:
Once you have created an instance of UILocalNotification, you schedule it using one of two methods of the UIApplication class: scheduleLocalNotification: or presentLocalNotificationNow:. The former method use the fire date to schedule delivery; the latter method presents the notification immediately, regardless of the value of fireDate. You can cancel specific or all local notifications by calling cancelLocalNotification: or cancelAllLocalNotifications, respectively.
关于ios - presentLocalNotificationNow 和 scheduleLocalNotification 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19751536/
我有一个应用程序调用 scheduleLocalNotification ,但是当我将其安装到 /Applications 而不是 /var/mobile/Applications 时,它不起作用:
我正在使用来自AppDelefate的scheduleLocalNotification作为UILocalNotification,并且调试配置一切顺利。但是,当我在临时设置上测试我的应用程序时 -
我正在尝试设置重复提醒...我正在使用此代码: UILocalNotification *localNotif = [[UILocalNotification alloc] init];
当我从 dateTimePicker.date 获取时间/日期时,通知有效,但当我使用 dateFromString 触发日期时,通知无效。 代码: -(IBAction)alarmSetButton
在我们的应用中,如果用户设置了我们的 future 提醒,我们会通过以下方式设置本地通知: UILocalNotification *localNotif = [[UILocalNotificatio
不知道是不是技术问题。我试图通过调用这个来实现预定的本地通知: // Schedule the notification ***************************************
我的应用程序有时需要安排近 64 个本地通知,这将在 iPhone4 上阻塞我的主线程近 1 秒。我想在一个单独的线程上执行此操作,UIApplcation 线程的这些本地通知操作方法安全吗? 最佳答
调用scheduleLocalNotification:后在 UIApplication 上单例,我注意到在一些场合 scheduledLocalNotifications 返回的通知数组在 UIAp
我正在使用 UILocalNotification 问题是当我使用 scheduleLocalNotification 发布我的通知时,它永远不会触发 didReceiveLocalNotificat
我遇到了 scheduleLocalNotification 的性能问题。我正在尝试注册大量本地通知。这就像 friend 的生日闹钟。为了测试,我尝试注册大约 300 个通知,但我的 iPhone4
presentLocalNotificationNow 和 scheduleLocalNotification 有什么区别。 因为以下两个函数都是在 1 秒后显示通知 -(void)showLocal
我在为我的 iOS 应用程序设置带有计划本地通知的图标角标(Badge)时遇到了一些困难。 当我在加载应用程序后单击主屏幕时,我能够在 10 秒后触发本地通知弹出。但是,未设置应用程序图标角标(Bad
我在我的 info.plist 中设置了“应用程序不在后台运行”,所以当用户点击主页按钮时,应用程序退出。 当我的 [UIApplication -appWillTerminate:] 被调用时,我将
我是 iOS 技术的新手。我正在尝试使用 UILocalNotification 使用 swift 2.0 构建一个闹钟应用程序。当我单击按钮时,我从 UIPickerView 获取时间和日期。我也想
有谁知道“PushNotificationIOS”方法“scheduleLocalNotification”的“fireDate”对象的日期和时间格式 提前致谢 最佳答案 我在向 fireDate 发
native react :0.44.3 目标平台:iOS 开发操作系统:macOS Sierra 10.12.4 构建工具:XCode 这种行为会导致一个非常令人困惑的错误,即预定通知在模拟器上按预
我是一名优秀的程序员,十分优秀!