PubNub AngularJS error in push config: 'Pubnub.push.addChannels' is undefined - angularjs

Using PubNub and trying to setup push for ios (apns) per their docs.
The following generates the error:
var initPubnubPush = function(token) {
Pubnub.push.addChannels(
{
channels: ['my_first_channel'],
device: token,
pushGateway: 'apns' // apns, gcm, mpns
},
function(status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
}
I have their publish/subscribe working on the channel my_first_channel and push should work when the app is in background. The token is valid and is returned from
pushNotification.register(
tokenHandler,
errorHandler,
{
'badge':'true',
'sound':'true',
'alert':'true',
'ecb':'onNotificationAPN'
}
);
function tokenHandler(token) {
// This is a device token you will need later to send a push
// Store this to PubNub to make your life easier :-)
initPubnubPush(token);
}
The complete error in Safari console while running on real iPhone device:
Error in Success callbackId: PushPlugin63370093 : TypeError:
Pubnub.push.addChannels is not a function.
(In 'Pubnub.push.addChannels', 'Pubnub.push.addChannels' is undefined)
Can't find anything in google for this error.

Turns out there is a bug in the PubNub Angular library and that method push.addChannels is not properly delegated.

Related

Reactjs Integration Testing Cognito Native Crypto Module Could Not Be Used To Get Secure Random Number

I have an integration test that uses the AWS Cognito library; specifically, I'm calling CognitoUser.authenticateUser(). When I start my webpage this all works fine: however, in my tests I'm getting the following error:
Error: Native crypto module could not be used to get secure random number.
at cryptoSecureRandomInt (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/utils/cryptoSecureRandomInt.web.js:38:9)
at WordArray.random (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/utils/WordArray.js:50:56)
at randomBytes (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/AuthenticationHelper.js:47:58)
at AuthenticationHelper.generateRandomSmallA (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/AuthenticationHelper.js:113:21)
at new AuthenticationHelper (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/AuthenticationHelper.js:67:29)
at CognitoUser.authenticateUserDefaultAuth (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:264:32)
at CognitoUser.authenticateUser (/source/project/master/website/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:237:19)
Researching for answers I came across many posts suggesting:
Object.defineProperty(global.self, 'crypto', {
value: {
getRandomValues: arr => crypto.randomBytes(arr.length),
}
});
Unfortunatley that does not work.
Looking at the crypto source:
function cryptoSecureRandomInt() {
if (crypto) {
// Use getRandomValues method (Browser)
if (typeof crypto.getRandomValues === 'function') {
try {
return crypto.getRandomValues(new Uint32Array(1))[0];
} catch (err) {}
} // Use randomBytes method (NodeJS)
if (typeof crypto.randomBytes === 'function') {
try {
return crypto.randomBytes(4).readInt32LE();
} catch (err) {}
}
}
throw new Error('Native crypto module could not be used to get secure random number.');
}
I can see where this error is being thrown. I'm guessing that under normal circumstances the crypto package is loaded by the browser which obviously doesn't exist when testing.
Any suggestions?
Update 1
Stepped through using the debugger and in the crypto source it's getting undefined for the 'crypto' variable on this line
if (crypto) {
This means that the Object.defineProperty is not working. I tried attaching it to the window but that doesn't work either
Object.defineProperty(window, 'crypto', {
value: {
getRandomValues: (arr) => crypto.randomBytes(arr.length)
}
});

TypeError: undefined is not an object (evaluating 'PushNotifications.register') - Capacitor 3

I've been trying to implement push notifications in my Ionic/React app, however I'm having an issue importing the package and using it in my component. The example here (Step 4) suggests importing it like below
import { PushNotification, PushNotificationActionPerformed, PushNotificationToken } from '#capacitor/push-notifications';
const {PushNotifications} = Plugins;
Then calling a push method which handles the logic of the PushNotifications plugin.
push() {
PushNotifications.register();
// On succcess, we should be able to receive notifications
PushNotifications.addListener('registration',
(token: PushNotificationToken) => {
alert('Push registration success, token: ' + token.value);
}
);
// Some issue with your setup and push will not work
PushNotifications.addListener('registrationError',
(error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
}
);
// Show us the notification payload if the app is open on our device
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotification) => {
console.log(`Notification received: ${notification}`);
}
);
// Method called when tapping on a notification
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: PushNotificationActionPerformed) => {
console.log(`Notification tapped: ${notification}`);
}
);
}
However doing this and running the app gives me an error saying
TypeError: undefined is not an object (evaluating 'PushNotifications.register')
It's worth noting that all the imports say they're deprecated with a line-strike across each of them, but I'm not sure where the working ones are or how to import them. Any help would be greatly appreciated.

failed to register error on push notification mobilefirst 8.0

In my application I use MobileFirst Platform push notification,
MFPPush.registerDevice(
function(successResponse) {
alert("Successfully registered");
},
function(failureResponse) {
alert("Failed to register"+failureResponse);
}
);
I get the following error,
"Failed to register
com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushException
:Response:status=400,Text:"Invalid request body JSON mapping
failed",Error Message:Bad Request"
Have you created a scope "push.mobileclient" ? If not please got to Security and create above scope . After that add above block inside success callback of WLAuthorizationManager.obtainAccessToken("push.mobileclient").then().

cordovaGeolocation error: position retrieval timed out

Hello I want to implement some geolocation features in my app.
So I implemented a watchposition function like this:
.controller('NavigationCtrl', function ($scope,$cordovaGeolocation) {
var watchOptions = {
frequency : 1000,
timeout : 20*1000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
alert("WatchPosition failed: "+JSON.stringify(err));
},
function(position) {
$scope.position = position;
}
);
})
Well in the first call of the template I get a geolocation but than after 20 seconds I get an error:
code:3, message:'Position retrieval timed out'
I'm testing the app on a iPhone 5s iOS 8.3.
I googled around and found out that cordova 3.1 has some errors with geolocations so I choose to use the html api for geolocations like here:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation
but it didn't show me anything in my ionic-framework app.
What am I missing?
I'm using cordova 4.3.0 and ionic 1.3.19.
I found out that I have to put the code in a $ionicPlatform.ready function to be sure that the device is ready before it start geolocating. Now it working fine.

angular ngressource issue TypeError: Cannot read property 'get' of undefined

I'm new to angular and I'm trying to to create a service to register and login users using a spring rest controller, below is the Angular code to retrive Json data
.factory('accountService', function($resource) {
var service = {};
service.register = function(account, success, failure) {
var Account = $resource("/mywebapp/rest/account");
Account.save({}, account, success, failure);
};
service.userExists = function(account, success, failure) {
var Account = $resource("/mywebapp/rest/account");
var data = account.get({email:'email'}, function() {
var accounts = data.accounts;
if(accounts.length !== 0) {
success(accounts[0]);
} else {
failure();
}
},
failure);
};
return service;
})
the problem is that i'm getting two type of error message in chrome and FireFox when trying to connect (service.userExists):
TypeError: Cannot read property 'get' of undefined
at Object.service.userExists (http://localhost:8080/mywebapp/resources/js/account.js:42:27)
at h.$scope.login (http://localhost:8080/mywebapp/resources/js/account.js:56:24)
at http://localhost:8080/mywebapp/resources/lib/angular/angular.js:178:68
at f (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:177)
at h.$eval (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:32)
at h.$apply (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:310)
at HTMLFormElement.<anonymous> (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:229)
at http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:225
at r (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:7:290)
at HTMLFormElement.c (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:207)
and in firefox:
"Error: account is undefined
service.userExists#http://localhost:8080/mywebapp/resources/js/account.js:42:13
$scope.login#http://localhost:8080/mywebapp/resources/js/account.js:56:1
gb.prototype.functionCall/<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:178:66
jc[c]</<.compile/</</f#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:177
Yd/this.$get</h.prototype.$eval#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:28
Yd/this.$get</h.prototype.$apply#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:305
jc[c]</<.compile/</<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:227
ne/c/<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:223
r#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:7:288
ne/c#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:207
i'm also getting this error when trying to register a new account:
[HTTP/1.1 415 Type de Support Non Supporté 98ms]
Would you please help me.
ng-resource seems to never receive the account parameter which means the get request is not returning the account. Check the network tools to see what the userExists request is returning from the server.
The message your are receiving for the register could be a hint, I would say it means the API doesn't support your type of client, maybe you're using an old browser or a the server API is very old.

Resources