"gamecenter undefined" using a Game Center Cordova plugin - javascript

What am i doing wrong? I have set up Game Center in Xcode and iTunes connect, but yet in Javascript... I get an error saying gamecenter is not defined when I try to authenticate the user.
PLUGIN: https://github.com/leecrossley/cordova-plugin-game-center
var successCallback = function (user) {
alert(user.alias);
// user.alias, user.playerID, user.displayName
};
gamecenter.auth(successCallback, failureCallback);
My full JS code is here: https://github.com/GunZi200/Memory-Colour/blob/master/test.js
the first thing my program should do is authenticate the user[nothing happens], how come gamecenter isn't defined?

You have to wait for the device ready event before trying to use a plugin
document.addEventListener("deviceready", authUser, false);
function authUser(){
gamecenter.auth(successCallback, failureCallback);
}

Related

"ScriptError: Authorisation is required to perform that action." when running google.script.run from Library

Regards,
I have found several questions regarding this error :
"ScriptError: Authorisation is required to perform that action." but I can't find one that is about my issue.
What I am trying to do is call a function .gs file from .html file using google.script.run where both of the file is in Library. Referring to this answer, this answer and this bug report, I have created the "wrapper function" in the script that is using the library, but still failed to finish the execution.
Here's what I did :
.html in Library :
<html>
<head>
<script>
function onFailure(error) {
console.log("ERROR: " + error);
}
function myfunc() {
console.log("HERE");
google.script.run.withFailureHandler(onFailure).callLibraryFunction('LibraryName.test', ['test123']);
}
</script>
</head>
<body>
<button onclick="myfunc()">CLICK</button>
</body>
</html>
.gs in Library
function test(x){
Logger.log(x);
}
.gs in script that is using the Library:
function callLibraryFunction(func, args) {
var arr = func.split(".");
var libName = arr[0];
var libFunc = arr[1];
args = args || [];
return this[libName][libFunc].apply(this, args);
}
The console logs HERE but then it logs ERROR: ScriptError: Authorisation is required to perform that action. instead of the expected output, test123.
NOTE: The HTML is for custom modeless dialog box in Sheets and not for Web App.
I really hope someone can help me in this. Thank you in advance.
You need to grant access of the library "LibraryName" as an authorized app in your Gmail account the same way how you grant access to the calling script. I guess you have called the method HtmlService.createHtmlOutputFromFile(...) in your library. This requires more authorization. You need to grant this. What you can do is create a temporary function in the library that has HtmlService.createHtmlOutputFromFile(..). Run it from the script editor and the authorization requirement window appears. Proceed in granting access...

OneSignal push notification handle in angularjs controller

i have problem with handling OneSignal pushNotification in cordova app. My purpose is open display page from any controllers, every page has specific controller. Whenever notification come will do same thing, open display page. My code is here :
index.html
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
var notificationOpenedCallback = function(jsonData) {
//do some thing
};
window.plugins.OneSignal
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
}
controller
app.controller('startController', function ($scope, $http) {
var notificationOpenedCallback = function (jsonData) {
$scope.myNavigator.pushPage('form/displaypage.html');
};
window.plugins.OneSignal //get error : Uncaught TypeError: Cannot read property 'OneSignal' of undefined
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx)
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
});
How to put windos.plugins.OneSignal in controllers?
For cordova apps, you need to add the OneSignal plugin first. In the terminal, at the root of your cordova application, do
cordova plugin add onesignal-cordova-plugin
If you want to save this plugin to your config.xml, add the --save flag to the end of the command. This comes in handy if you're using shared version control.
This will install and register the plugin. You should then rebuild the project and try again on your device.
Further information about setup with the Cordova SDK can be found here

Uncaught TypeError: Cannot read property 'OneSignal' of undefined", source: file:///android_asset/www/js/app

I'm trying to initialize OneSignal to a PhoneGap application.
I tried many ways. But always it gives following error,
Uncaught TypeError: Cannot read property 'OneSignal' of undefined",
source: file:///android_asset/www/js/app.js error.
This is my app.js file
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
oneSignal();
checkConnection();}
function oneSignal(){
console.log("It is calling");
var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal.init("my app id",
{googleProjectNumber: "my project number"},
notificationOpenedCallback);
// Show an alert box if a notification comes in when the user is in your app.
window.plugins.OneSignal.enableInAppAlertNotification(true);}
Somebody please help me to initialize OneSignal to my PhoneGap application.
The best way to initialize OneSignal is by adding the code in your controller.js file and make sure its in one of your controllers - it might be login, logout, anything.
in other words you need to add the code inside a set controller that responds to a certain action.
Cant explain it better but try that -..
Good luck
Just try installing your plugin, cross verify for it's availability in the plugins folder. Also confirm the corresponding update has been made in config.xml and fetch.json (in the plugins folder). The error usually arises in case the plugin is not installed properly.
Hope this helps... :)

VS2015 Cordova Sms Plugin Sms.Send doesn't work in Index.JS (ondeviceReady)

I'm new to Cordova, any help would be appreciated.
I created a new Cordova Project in VS2015 and added the Cordova SMS plugin to my project (https://www.npmjs.com/package/cordova-sms-plugin).
I added this code to /www/scripts/index.js function onDeviceReady (as per documentiation for plugin):
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
var numberString = "aoeuaeu";
var bypassAppChooser = true;
//CONFIGURATION
var options = {
replaceLineBreaks: false,
android: {
intent: 'INTENT' // send SMS with the native android SMS messaging
}
};
var successSMS = function () { alert('Message sent successfully'); };
var errorSMS = function (e) { alert('Message Failed:' + e); };
sms.send("0811231234", "Testing123", options, successSMS, errorSMS);
I debug the project using Debug, Android, Ripple - Nexus (Galaxy) selected options. When I place a breakpoint on the sms.send line of code and I add a watch for 'sms.send', I can see the object exists.
When I single step, this line in sms.js seems to be the last line that executes:
// fire
exec(
success,
failure,
'Sms',
'send', [phone, message, androidIntent, replaceLineBreaks]
);
I then get the following error message in Ripple:
'Sms.send We seem to be missing some stuff :( What is kinda cool though you can fill in the textarea to pass a json object to the callback you want to execute).'
I can see that all of the objects in that line is defined (success, failure, phone, message, androidIntent, replaceLineBreaks). When I 'step into' this line, it continues to execute code in ripple.js, but it becomes hard to follow for a person, since there are no line breaks in this file.
What am I doing wrong? I've read through all the documentation I can find & searched stackoverflow questions and can't seem to find any solutions to the problem.
I've uploaded this entire project (zipped), which can be downloaded at:
https://drive.google.com/file/d/0BwWgTMh-JLbfNHV0MlE5Yk5IZ3M/view?usp=sharing
Thanks in advance
Thank you Cordova team at Microsoft for helping me with an answer:
"Ripple has the ability to emulate some but not all plugins. SMS is not one of the plugins that it can fully emulate. However, in the message that pops up, you do have the ability to hit the Success or Fail buttons which will report back to the app that it was successful or not in sending the SMS. While that doesn’t actually send a message, it does let you test your app to see how it behaves for different results.
I tried the bit of sample code you included in the first email. In Ripple, I was able to change the alert by hitting the different buttons.
Trying other deployment methods, in both the VS Android Emulator and the Google Emulator they showed failure alert messages that they don’t support SMS messages. I then launched it on an Android phone device and it said it was successful.
So I believe your options are mainly using Ripple to fake sending of messages or using a device for testing."

Why doesn't callback get called when the app is in background?

I'm developing a titanium app that needs to display a Banner Message under iOS when a push notification comes in. Therefore I used the following code to register on incoming push notifications:
var callbacks = {
types: [
Titanium.Network.NOTIFICATION_TYPE_BADGE,
Titanium.Network.NOTIFICATION_TYPE_SOUND,
Titanium.Network.NOTIFICATION_TYPE_ALERT
],
success:function(e){
console.log("success");
},
error:function(e){
console.log("error");
},
callback: function(e){
console.log("new push notification")
//code for displaying banner message would go here!
}
};
if(Ti.App.iOS.registerUserNotificationSettings){ //iOS 8 +
function onUserNotificationSettings(){
delete callbacks.types;
Ti.Network.registerForPushNotifications(callbacks);
Ti.App.iOS.removeEventListener("usernotificationsettings",onUserNotificationSettings);
}
Ti.App.iOS.addEventListener("usernotificationsettings",onUserNotificationSettings)
Ti.App.iOS.registerUserNotificationSettings(callbacks)
}else{ //up to iOS 7
Ti.Network.registerForPushNotifications(callbacks)
}
But the callback function does not get called when the app is in background. So, I also can't display the banner message there, since the code won't get executed.
What could be the reason why the callback does not get called when the app is in background? When it is in foreground, it works perfectly. Is it normal? If yes, where else would I put my code to display the banner message?
I'm using SDK version 3.4.0 on an iPhone 5 with iOS 8.1.1
Please note that sending the banner text through the apn-payload is not the solution. There are other usecases. For example, when the server needs to tell the client that there is new content to sync, where the user does not even need to get notified for. The client should just download the new content in background just when the notification arrives.
You need to register for the remote-notification background mode. This will wake up your app and give you execution time when you send the notifications.
For the record this is in the Appcelerator docs here
I've found out how to do it!
The callback will get called when the app is in background. All I had to do for it was to add the following to my tiapp.xml in ti:app/ios/plist/dict:
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
After that, everything works fine!

Categories

Resources