This question is locked. New answers and comments are not allowed.
Hi, I try to do a push notification and below is the portion of the codes I used from the sample.
1. I manage to get a device (Android) registered and appear in the Devices List.
2. When I try to send Push Notification, it will show there is 1 Active device.
3. But the device never receive the push notification.
4. Next I check again the devices is shown as Not Active.
5. I also try to run the Sample directly and it can work and receive the Push Notification, so I think the problem might lies in my apps' code and not the device.
6. Is there anything I miss out?
1. I manage to get a device (Android) registered and appear in the Devices List.
2. When I try to send Push Notification, it will show there is 1 Active device.
3. But the device never receive the push notification.
4. Next I check again the devices is shown as Not Active.
5. I also try to run the Sample directly and it can work and receive the Push Notification, so I think the problem might lies in my apps' code and not the device.
6. Is there anything I miss out?
001.//This is your Telerik BackEnd Services API key.002.var baasApiKey = 'removed';003. 004.//This is the scheme (http or https) to use for accessing Telerik BackEnd Services.005.var baasScheme = 'http';006. 007.//This is your Android project number. It is required by Google in order to enable push notifications for your app. You do not need it for iPhone.008.var androidProjectNumber = 'removed';009. 010.//Set this to true in order to test push notifications in the emulator. Note, that you will not be able to actually receive011.//push notifications because we will generate fake push tokens. But you will be able to test your other push-related functionality without getting errors.012.var emulatorMode = false;013. 014. 015.var deviceready = function () {016. 017. alert('//Initialize the Everlive SDK');018. //Initialize the Telerik BackEnd Services SDK019. var el = new Everlive({020. apiKey: baasApiKey,021. scheme: baasScheme022. });023. 024. 025. var successText = "SUCCESS!<br /><br />The device has been initialized for push notifications.<br /><br />";026. 027. var _onDeviceIsRegistered = function() {028. $("#initializeButton").hide();029. $("#registerButton").hide();030. $("#unregisterButton").show();031. $("#messageParagraph").html(successText + "Device is registered in Telerik BackEnd Services and can receive push notifications.");032. };033. 034. var _onDeviceIsNotRegistered = function() {035. $("#unregisterButton").hide();036. $("#registerButton").show();037. $("#messageParagraph").html(successText + "Device is not registered in Telerik BackEnd Services. Tap the button below to register it.");038. };039. 040. var _onDeviceIsNotInitialized = function() {041. $("#unregisterButton").hide();042. $("#initializeButton").show();043. $("#messageParagraph").html("Device unregistered.<br /><br />Push token was invalidated and device was unregistered from Telerik BackEnd Services. No push notifications will be received.");044. };045. 046. var _onDeviceRegistrationUpdated = function() {047. $("#messageParagraph").html("Device registration updated.");048. };049. 050. var onAndroidPushReceived = function(args) {051. alert('Android notification received: ' + JSON.stringify(args));052. };053. 054. var onIosPushReceived = function(args) {055. alert('iOS notification received: ' + JSON.stringify(args));056. };057. 058. //Initializes the device for push notifications.059. var enablePushNotifications = function () {060. //Initialization settings061. var pushSettings = {062. android: {063. senderID: androidProjectNumber064. },065. iOS: {066. badge: "true",067. sound: "true",068. alert: "true"069. },070. notificationCallbackAndroid : onAndroidPushReceived,071. notificationCallbackIOS: onIosPushReceived072. }073. 074. $("#initializeButton").hide();075. $("#messageParagraph").text("Initializing push notifications...");076. 077. var currentDevice = el.push.currentDevice(emulatorMode);078. 079. currentDevice.enableNotifications(pushSettings)080. .then(081. function(initResult) {082. $("#tokenLink").attr('href', 'mailto:test@example.com?subject=Push Token&body=' + initResult.token);083. $("#messageParagraph").html(successText + "Checking registration status...");084. return currentDevice.getRegistration();085. },086. function(err) {087. $("#messageParagraph").html("ERROR!<br /><br />An error occured while initializing the device for push notifications.<br/><br/>" + err.message);088. }089. ).then(090. function(registration) { 091. _onDeviceIsRegistered(); 092. },093. function(err) { 094. if(err.code === 801) {095. _onDeviceIsNotRegistered(); 096. }097. else { 098. $("#messageParagraph").html("ERROR!<br /><br />An error occured while checking device registration status: <br/><br/>" + err.message);099. }100. }101. );102. };103. 104. var registerInEverlive = function() {105. var currentDevice = el.push.currentDevice();106. 107. if (!currentDevice.pushToken) currentDevice.pushToken = "some token";108. el.push.currentDevice()109. .register({ Age: 15 })110. .then(111. _onDeviceIsRegistered,112. function(err) {113. alert('REGISTER ERROR: ' + JSON.stringify(err));114. }115. );116. };117. 118. var disablePushNotifications = function() {119. el.push.currentDevice()120. .disableNotifications()121. .then(122. _onDeviceIsNotInitialized,123. function(err) {124. alert('UNREGISTER ERROR: ' + JSON.stringify(err));125. }126. );127. };128. 129. var updateRegistration = function() {130. el.push.currentDevice()131. .updateRegistration({ Age: 16 })132. .then(133. _onDeviceRegistrationUpdated,134. function(err) {135. alert('UPDATE ERROR: ' + JSON.stringify(err));136. }137. );138. };139. 140. 141. enablePushNotifications();142. 143. registerInEverlive();144. 145.};