【问题标题】:How to banner notification when application foreground swift 2 with iOS 9ios 9应用程序前台swift 2时如何横幅通知
【发布时间】:2017-06-25 21:59:48
【问题描述】:

当应用程序停留在后台(远程通知)时,它工作正常。问题是当我和我的一位朋友聊天时。我需要显示来自其他联系人的新消息,例如 Facebook Messenger 等 iOS 通知提醒横幅。我的设备通知列表中还有可用的通知。我不知道该怎么做..

我找到了答案 Displaying a stock iOS notification banner when your app is open and in the foreground? 但它是 iOS 10 。我需要支持最低 iOS 9 并且项目是 swift 2

【问题讨论】:

  • 当您在与其他人聊天时收到来自其他用户的消息时,您可以使用 UIview 显示自定义通知。您将在应用委托中的接收功能中收到通知。然后,如果新通知来自不同的用户,则在窗口顶部显示自定义视图。
  • @Prince .ok 很好 .. 我怎样才能发出通知声音
  • 播放通知声音,您可以搜索 SO,这可能会对您有所帮助。 stackoverflow.com/questions/3277811/…

标签: ios push-notification swift2 ios9


【解决方案1】:

将 completionHandler 行添加到 appDelegate 方法解决了我的问题:

//Called when a notification is delivered to a foreground app.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("User Info = ",notification.request.content.userInfo)

completionHandler([.alert, .badge, .sound])
} 

【讨论】:

  • 这是iOS10。不是 iOS9。
猜你喜欢
  • 1970-01-01
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-15
  • 2018-06-14
  • 2017-05-11
相关资源
最近更新 更多