Created
January 13, 2016 20:47
-
-
Save macdonst/191f74ac75b6802c047d to your computer and use it in GitHub Desktop.
This file contains 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
var app = { | |
// Application Constructor | |
initialize: function() { | |
this.initPush(); | |
this.bindEvents(); | |
}, | |
// Bind Event Listeners | |
// | |
// Bind any events that are required on startup. Common events are: | |
// 'load', 'deviceready', 'offline', and 'online'. | |
bindEvents: function() { | |
document.addEventListener('deviceready', this.onDeviceReady, false); | |
}, | |
// deviceready Event Handler | |
// | |
// The scope of 'this' is the event. In order to call the 'receivedEvent' | |
// function, we must explicitly call 'app.receivedEvent(...);' | |
onDeviceReady: function() { | |
console.log('device is ready'); | |
}, | |
initPush: function() { | |
var push = PushNotification.init({ | |
"android": { | |
"senderID": "1234567890" | |
}, | |
"ios": {"alert": "true", "badge": "true", "sound": "true"}, | |
"windows": {} | |
}); | |
push.on('registration', function(data) { | |
console.log("registration event"); | |
document.getElementById("regId").innerHTML = data.registrationId; | |
console.log(JSON.stringify(data)); | |
}); | |
push.on('notification', function(data) { | |
console.log("notification event"); | |
console.log(JSON.stringify(data)); | |
var cards = document.getElementById("cards"); | |
var card = '<div class="row">' + | |
'<div class="col s12 m6">' + | |
' <div class="card darken-1">' + | |
' <div class="card-content black-text">' + | |
' <span class="card-title black-text">' + data.title + '</span>' + | |
' <p>' + data.message + '</p>' + | |
' </div>' + | |
' </div>' + | |
' </div>' + | |
'</div>'; | |
cards.innerHTML += card; | |
push.finish(function () { | |
console.log('finish successfully called'); | |
}); | |
}); | |
push.on('error', function(e) { | |
console.log("push error"); | |
}); | |
} | |
}; | |
app.initialize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have complete following procedure:
but this function "push.on('registration', function(data) {" never get call back and never get registrationId. :(
someone please help me here.I am using "build.phonegap.com" to build project.
I want to setup this for IOS only.
thanks :)