【发布时间】:2017-08-09 20:10:43
【问题描述】:
我是 Swift 新手,现在我正在开发一个 iOS 应用程序,它必须向用户发送实时用户通知。与聊天应用程序一样,当用户收到新消息时,iPhone 必须发送通知。就我而言,我只需要通知,但它们必须是实时的。当一个用户点击一个按钮时,另一个应该收到通知。我读过很多文章和问题,但我从来没有找到一个很好的例子。我在我的应用中安装了 OneSignal 和 FireBase pod 文件,我可以将通知从他们的服务器发送到应用,但现在我需要在设备之间发送通知。
使用以下代码,我得到了用户 ID:
func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
if !stateChanges.from.subscribed && stateChanges.to.subscribed {
print("Subscribed for OneSignal push notifications!")
}
print("SubscriptionStateChange: \n\(stateChanges)")
//The player id is inside stateChanges. But be careful, this value can be nil if the user has not granted you permission to send notifications.
if let playerId = stateChanges.to.userId {
print("Current playerId \(playerId)")
}
}
但是我如何使用这个 ID 向它发送通知。 任何示例或建议将不胜感激。
【问题讨论】:
-
为了向设备发送消息,您需要设置一个网络服务来处理您的请求并将必要的数据发送到 Firebase 服务。
-
我查看了您发送给我的链接,不幸的是它没有为我的问题提供答案:(
-
@Barns52 有什么例子吗?
-
您是否创建了 Apple 推送通知证书并正确配置了 Firebase 云通知 APN?此外,您的 iOS 项目中的推送通知是否“开启”-> 启用通知权利的功能?
标签: firebase swift3 push-notification onesignal