在 App Store 中发送推送通知应用 public
Send Push Notifications App in App Store public
抱歉,我是这方面的新手,我一无所获。我关注了this tutorial and everything works fine. Now my app is in the app store available. How to send the push notifications to all the users? I am somewhat bemused about the "Enter device token"-Field in the Push Notifications Tool。为什么要输入设备令牌,我想将通知发送给用户,而不仅仅是我的设备?还是我理解有误?
为了发送推送通知,您的 Push Notification Tool
需要知道它必须将通知发送到哪个设备。为此,您需要 Device Token
。您可以为每个用户设置多个 Device Token
,并且您的 Push Notification Tool
会向存储了 Device Token
的所有设备推送通知。您不能根据 user id
或其他此类字段发送推送通知。
编辑:
这就是您获取 deviceToken 的方法。您需要在 AppDelegate
中添加此功能
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
}
注:
确保您已按照问题中提到的教程进行操作。您需要注册通知并按照在您的应用程序上设置推送通知所需的所有步骤进行操作。如果您的应用未注册推送通知,则上述功能可能无法使用。我只发布了一种方法,假设您已经遵循并实施了教程中的所有内容。
抱歉,我是这方面的新手,我一无所获。我关注了this tutorial and everything works fine. Now my app is in the app store available. How to send the push notifications to all the users? I am somewhat bemused about the "Enter device token"-Field in the Push Notifications Tool。为什么要输入设备令牌,我想将通知发送给用户,而不仅仅是我的设备?还是我理解有误?
为了发送推送通知,您的 Push Notification Tool
需要知道它必须将通知发送到哪个设备。为此,您需要 Device Token
。您可以为每个用户设置多个 Device Token
,并且您的 Push Notification Tool
会向存储了 Device Token
的所有设备推送通知。您不能根据 user id
或其他此类字段发送推送通知。
编辑:
这就是您获取 deviceToken 的方法。您需要在 AppDelegate
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
}
注: 确保您已按照问题中提到的教程进行操作。您需要注册通知并按照在您的应用程序上设置推送通知所需的所有步骤进行操作。如果您的应用未注册推送通知,则上述功能可能无法使用。我只发布了一种方法,假设您已经遵循并实施了教程中的所有内容。