Created
September 25, 2018 06:51
-
-
Save florindumitru/e7df8edff6002b5e6f31809f32b0cc21 to your computer and use it in GitHub Desktop.
Registering a Parse Installation with React Native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Not published on npm! use this fork https://github.com/gpbl/react-native-device-info | |
| import DeviceInfo from "@gpbl/react-native-device-info"; | |
| const PARSE_URL = "https://api.parse.com/1/installations"; | |
| const PARSE_APP_ID = "YOUR_APP_ID"; | |
| const PARSE_REST_KEY = "YOUR_REST_KEY"; | |
| function registerParseInstallation(pushToken) { | |
| const data = { | |
| appIdentifier: DeviceInfo.appIdentifier, | |
| appName: DeviceInfo.appName, | |
| appVersion: DeviceInfo.appBuildNumber, | |
| appShortVersion: DeviceInfo.appVersion, | |
| deviceToken: pushToken, | |
| deviceType: "ios", | |
| installationId: DeviceInfo.installationId, | |
| localeIdentifier: DeviceInfo.localeIdentifier, | |
| parseVersion: "1.9.0", | |
| timeZone: DeviceInfo.timeZone | |
| }; | |
| return fetch(PARSE_URL, { | |
| method: "POST", | |
| headers: { | |
| "Accept": "application/json", | |
| "X-Parse-Application-Id": PARSE_APP_ID, | |
| "X-Parse-REST-API-Key": PARSE_REST_KEY, | |
| "Content-Type": "application/json" | |
| }, | |
| body: JSON.stringify(data) | |
| }) | |
| .then(response => { | |
| if (!response.ok) { | |
| throw response; | |
| } | |
| return response.json(); | |
| }) | |
| .then({ objectId } => { | |
| console.log("Parse Installation registered successfully with objectId=%s", objectId); | |
| return objectId; | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment