简体   繁体   English

在实践中反应原生推送通知

[英]React Native Push Notifications in Practice

I've successfully implemented Push Notifications on React Native, by pushing messages via my device token.我已经通过我的设备令牌推送消息,成功地在 React Native 上实现了推送通知。 In production, when the app is in the store, what's the optimal method for obtaining device tokens from users who download our app and enabled push notifications.在生产中,当应用程序在商店中时,从下载我们的应用程序并启用推送通知的用户那里获取设备令牌的最佳方法是什么。 Should we have the app push a unique identifier + device token to our server when opening the app?打开应用程序时,我们是否应该让应用程序将唯一标识符 + 设备令牌推送到我们的服务器? Or is there a more efficient approach?或者有没有更有效的方法?

Obtain the token every time the app becomes active, cache it within the app and send it to the server (via http push for example) Next time the app obtains the token compare it with the cached version, if they differ send the new one to the server and cache the new old.每次应用程序激活时获取令牌,将其缓存在应用程序中并将其发送到服务器(例如通过 http 推送) 下次应用程序获取令牌时将其与缓存版本进行比较,如果它们不同,则将新的发送到服务器并缓存新的旧的。

If you also send a unique id depends upon your push requirements, there's no use for it if you are broadcasting pushes to all devices.如果您还发送一个唯一的 id 取决于您的推送要求,那么如果您向所有设备广播推送,则它没有用。 If you send pushes to specific handsets then obviously some identifier is needed to identify the user/device.如果您向特定手机发送推送,那么显然需要一些标识符来识别用户/设备。

1- You need paid apple developer account 1-您需要付费的苹果开发者帐户

2- You need to generate .pem file to use in server side from here 2- 您需要从此处生成.pem文件以在服务器端使用

3- In appdelegate.m use 3- 在appdelegate.m使用

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//here you call your web service to record device token to server
}

4- prepare your server side from here 4- 从这里准备您的服务器端

5- you will need two .pem file one to development mode and another for production mode 5- 您将需要两个.pem文件,一个用于开发模式,另一个用于生产模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM