使用时xcode 8做推送通知设置,不像xcode 7,xcode 8需要推送通知功能切换开发商转(位于TARGETS -> AppName -> Capabilities如下图),

然后它将生成AppName.entitlements文件,如下所示
//AppName.entitlements
<key>aps-environment</key>
<string>development</string>
Run Code Online (Sandbox Code Playgroud)
但对于生产版App,如果我们将字符串更改为
//AppName.entitlements
<key>aps-environment</key>
<string>production</string>
Run Code Online (Sandbox Code Playgroud)
然后功能显示警告
似乎无论在aps-environment中指定了哪个字符串值,我们仍然可以获得推送设备令牌 application:didRegisterForRemoteNotificationsWithDeviceToken:
那么推送通知权利的正确设置是什么?谢谢
push-notification ios10 xcode8 unnotificationrequest xcode8-beta6
我有一个包含多个本地通知的应用.当我尝试清除所有已发送的通知时,我称之为此removeAllDeliveredNotifications方法.它工作正常,直到ios 11.1.在ios 11.2以上,预期这是行不通的.通知仍保留在通知中心.有人可以帮我解决这个问题.
提前致谢.
在UILocalNotification我们使用NSCalendarUnitMinute像重复.....但我在iOS 10 UserNotification doc中找不到...我怎样才能NSCalendarUnitMinute在iOS 10中使用类似的重复UserNotification?
这是代码,它将在晚上8:30安排本地通知,并在每一分钟后重复.
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.textField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = NSCalendarUnitMinute;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Run Code Online (Sandbox Code Playgroud) 我试图找到UNNotificationRequest对象的预定开火日期.
我正在提取这样的待处理通知请求:
UNUserNotificationCenter.current().getPendingNotificationRequests { (notifications) in
let pendingNotifications : [UNNotificationRequest] = notifications
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试访问每个UNNotificationRequest对象的触发日期.
我可以按如下方式访问UNNotificationTrigger,但无法找到访问通知的计划发布日期的方法.
let notification = pendingNotifications[indexOfNotification]
let trigger : [UNNotificationTrigger] = notification.trigger
Run Code Online (Sandbox Code Playgroud)
我已经能够访问一些通知的日期,如下所示:
let date = trigger.value(forKey: "date") as! Date
Run Code Online (Sandbox Code Playgroud)
这适用于使用UNUserNotificationCenter安排的通知,但在尝试访问iOS 10之前安排的通知日期时出现以下错误.
由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是关键日期的密钥值编码兼容.
是否有一种方法可以同时支持新旧通知.
谢谢.
我知道UILocalNotification的本地通知限制为64 .它是用Apple Dev Docs编写的.但UILocalNotification在iOS 10中已弃用.相反,Apple建议使用UNNotificationRequest.但Apple Dev Docs没有说明限制通知的数量.我找到了这个答案,但它没有Apple Dev Docs的链接或类似的东西(这只是一个意见).有没有人确切知道本地通知的限制?也许有人知道Dev Docs的链接,还是苹果对此有官方回应?
我正在使用UNNotificationRequest并且我希望当我单击按钮时立即弹出通知。但在这种情况下,它出现在我退出应用程序时。这是我的代码
@IBAction func shortNotifBtn(_ sender: Any) {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Late wake up call"
content.body = "The early bird catches the worm, but the second mouse gets the cheese."
content.categoryIdentifier = "alarm"
content.userInfo = ["customData": "fizzbuzz"]
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
}
Run Code Online (Sandbox Code Playgroud) 我尝试测试一种简单的方法,该方法应该为iOS 10创建并传递通知。
func displayPlaceNotificationContent() {
let unMutableNotificationContent = generateNotification()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: getNotificationIdentifier(), content: unMutableNotificationContent, trigger: trigger)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request, withCompletionHandler: nil)
}
Run Code Online (Sandbox Code Playgroud)
这是此方法的单元测试:
func testDisplayNotification() {
notificationManager?.displayPlaceNotificationContent())
XCTAssertTrue((notificationManager.isNotificationDisplayed())
}
Run Code Online (Sandbox Code Playgroud)
当我尝试执行单元测试时,我有一个异常,即堆栈跟踪:
2017-09-12 13:52:25.931564+0200 xctest[17170:1252988] *** Assertion failure in -[UNUserNotificationCenter initWithBundleProxy:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UserNotifications_Sim/UserNotifications-156/UNUserNotificationCenter.m:50
2017-09-12 13:52:25.933629+0200 xctest[17170:1252988] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleProxy != nil'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b0a9aeb __exceptionPreprocess …Run Code Online (Sandbox Code Playgroud) 这在 iOS 15 之前运行良好
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.sound = UNNotificationSound.init(named:UNNotificationSoundName(rawValue: sound))
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
Run Code Online (Sandbox Code Playgroud)
用户收到通知声音,iOS 15 之后我必须添加
content.body = "Hello iOS 15"
Run Code Online (Sandbox Code Playgroud)
无论如何,只能在 iOS 15 上发送带有声音的本地通知?
我的childAdded应用中的通知表有一个Firebase 事件监听器,我想在应用程序在后台时触发推送通知.
这是听众:
@objc func observeNotificationsChildAddedBackground() {
self.notificationsBackgroundHandler = FIREBASE_REF!.child("notifications/\(Defaults.userUID!)")
self.notificationsBackgroundHandler!.queryOrdered(byChild: "date").queryLimited(toLast: 99).observe(.childAdded, with: { snapshot in
let newNotificationJSON = snapshot.value as? [String : Any]
if let newNotificationJSON = newNotificationJSON {
let status = newNotificationJSON["status"]
if let status = status as? Int {
if status == 1 {
self.sendPushNotification()
}
}
}
})
}
func sendPushNotification() {
let content = UNMutableNotificationContent()
content.title = "Here is a new notification"
content.subtitle = "new notification push"
content.body = "Someone did something …Run Code Online (Sandbox Code Playgroud) ios firebase swift firebase-cloud-messaging unnotificationrequest
我正在尝试设置一个接收整数的函数,并在将来的n天内安排本地通知.我收到一个错误,我无法将类型Date转换为DateComponents.我无法弄清楚如何转换它.我在这里和这里找到了一些其他类似的问题,但我无法使这些答案适应Swift 3的工作.
如何将Date转换为DateComponents?有没有更好的方法来安排通知?
在此先感谢您的帮助 :)
带有错误的行,"无法转换类型'日期的值?' 预期的参数类型'DateComponents'":
let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false)
Run Code Online (Sandbox Code Playgroud)
功能齐全:
func scheduleNotification(day:Int) {
let date = Date()
let calendar = Calendar.current
var components = calendar.dateComponents([.day, .month, .year], from: date as Date)
let tempDate = calendar.date(from: components)
var comps = DateComponents()
//set future day variable
comps.day = day
//set date to fire alert
let fireDateOfNotification = calendar.date(byAdding: comps as DateComponents, to: tempDate!)
let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false) //THIS LINE CAUSES …Run Code Online (Sandbox Code Playgroud) ios ×9
ios10 ×4
swift ×4
firebase ×1
ios15 ×1
objective-c ×1
swift3 ×1
unit-testing ×1
xcode ×1
xcode8 ×1
xcode8-beta6 ×1