我正在开发基于本地通知的iPhone闹钟应用程序.
删除警报时,相关的本地通知应取消.但是,如何确定要取消本地通知数组中的哪个对象呢?
我知道[[UIApplication sharedApplication] cancelLocalNotification:notification]方法,但我怎么能得到这个'通知'取消它?
我有一个iPhone应用程序,可以接收推送通知.目前我可以通过转到iPhone设置/通知来禁用我的应用程序的推送通知.
但我想在我的应用程序中添加一个开关或按钮来启用或禁用推送通知.
它可以完成,因为我在foursqure看到它iphone应用程序做到了.他们在设置呼叫通知设置中有一个部分,用户可以启用或禁用该应用的不同类型的通知.
我在网上寻找一个合适的解决方案,但仍未找到方法.任何人都可以知道如何做到这一点?
提前致谢 :)
push-notification ios swift usernotifications unusernotificationcenter
说今天是星期一,下午1点.我想从今天下午2点开始,从我的iOS应用程序安排每周本地通知.我这样做:
NSDateComponents *components = [[[NSDateComponents alloc]init]autorelease];
components.weekday = 2;
components.hour = 14;
components.minute = 0;
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
//then make a UNMutableNotificationContent and UNNotificationRequest and schedule it
Run Code Online (Sandbox Code Playgroud)
但如果我想在下周一下午2点开始,我该如何跳过第一次?
要以另一种方式提出问题,如何UNCalendarNotificationTrigger在某个任意时间安排重复开始,而不是第一次出现重复间隔?
当用户收到通知并且我的应用程序处于后台时,如何打开我的应用程序?当然点击通知本身会打开应用程序,但如何使用自定义通知操作处理它?
我已经实现了UNUserNotificationCenterDelegate和userNotificationCenter(_,didReceive,...)
只需要一个可以打开我的应用程序并执行特定操作的代码(例如转到特定视图)
如果通知处理程序识别出通知并打开iPhone应用程序或Apple Watch应用程序取决于操作的位置,那将是很好的..
在我的应用中,我希望能够检查用户是否启用了通知.在iOS 10中,我使用委托中的检查来完成此操作.
现在不推荐使用此检查,我想更新它,但我无法弄清楚iOS 11中要使用的内容.
弃用警告如下:
在iOS 10.0中不推荐使用currentUserNotificationSettings:使用UserNotifications Framework - [UNUserNotificationCenter getNotificationSettingsWithCompletionHandler:]和 - [UNUserNotificationCenter getNotificationCategoriesWithCompletionHandler:]
我试图在这个警告的帮助下更新代码,但我无法弄清楚.
如果有人可以建议任何方式来获得这样的支票,那将会有很大帮助.我一直用于iOS 10的代码如下,谢谢.
let notificationType = UIApplication.shared.currentUserNotificationSettings!.types
if notificationType == [] {
print("Notifications are NOT enabled")
} else {
print("Notifications are enabled")
}
Run Code Online (Sandbox Code Playgroud) 我想使用iOS 10安排本地通知.我想知道如何做到这一点.我已经浏览了网络,但我一直在寻找线索,只是为了注册和处理通知.不适用于本地通知的安排.
那么,有谁知道怎么做?
我正在研究iOS 10的本地通知调度模块,它可以重复本地通知,例如每个星期天或每个星期一......等等.假设我安排了这个日期的通知,2016-12-27 10:53:22 +0000并且使用UNCalendarNotificationTrigger重复值等于true,通知会在该日期触发,并且不会在下周同时重复.
可能是什么原因?如何在iOS 10中的特定日期每周重复一次.
以下是创建本地通知的代码:
let content = UNMutableNotificationContent()
content.title = object.title
content.body = object.body
content.sound = UNNotificationSound.default()
let date = object.fireDate
let triggerDate = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second,], from: date as Date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate,
repeats: true)
// Swift
let identifier = object.id
let request = UNNotificationRequest(identifier: identifier,
content: content, trigger: trigger)
localNotification.add(request, withCompletionHandler: { (error) in
if error != nil {
// Something went wrong
print(error!)
}else {
print("Reminder \(object.id) has been added …Run Code Online (Sandbox Code Playgroud) 我正在安排本地通知.它适用于iOS 9.x但是从iOS 10开始
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Run Code Online (Sandbox Code Playgroud)
应用程序在iOS 10上运行时不会调用.
我知道iOS已经引入了新的UserNotifications框架,但不应该停止使用iOS 9 API.
我该如何解决这个问题?
如何UNNotificationSettings在iOS 10中使用获取通知类型?
在以前的iOS上,我会使用这个:
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
Bool active = notificationSettings.types == UIUserNotificationTypeNone ? NO: YES;
Run Code Online (Sandbox Code Playgroud) 我UIUserNotificationType.none在ViewController.swift上使用了Swift3,我得到了这个错误:'none'不可用user []来构造一个空的选项集; 这是我的代码:
func updateUI() {
let currentSettings = UIApplication.shared.currentUserNotificationSettings
if currentSettings?.types != nil {
if currentSettings!.types == [UIUserNotificationType.badge, UIUserNotificationType.alert] {
textField.isHidden = false
button.isHidden = false
datePicker.isHidden = false
}
else if currentSettings!.types == UIUserNotificationType.badge {
textField.isHidden = true
}
else if currentSettings!.types == UIUserNotificationType.none {
textField.isHidden = true
button.isHidden = true
datePicker.isHidden = true
}
}
}
Run Code Online (Sandbox Code Playgroud)