I am trying to implement push notification in ionic v1using onesignal-cordova-plugin,fcm.But it's not working.My app.js is given below - ionic-framework

var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal.init("MY APP ID",
{googleProjectNumber:"Project Number"},
notificationOpenedCallback);
// Show an alert box if a notification comes in when the user is in your app.
window.plugins.OneSignal.enableInAppAlertNotification(true);

Related

branch.io deeplink not working as expected in ionic 3

I have integrated branch.io deeplink in my ionic 3 application. I have successfully generated the link and the link opens up the app. But, I wanted to open a particular page instead of the homepage of the app.
So, I integrated the below code to the desired page:
dl(){
// only on devices
if (!this.platform.is('cordova')) { return }
const Branch = window['Branch'];
//only canonicalIdentifier is required
let properties = {
canonicalIdentifier: 'content/123',
canonicalUrl: 'https://example.com/content/123',
title: 'Content 123 Title',
contentDescription: 'Content 123 Description ' + Date.now(),
price: 12.12,
currency: 'GBD',
contentIndexingMode: 'private',
contentMetadata: {
custom: 'data',
testing: 123,
this_is: true
}
}
//create a branchUniversalObj variable to reference with other Branch methods
let branchUniversalObj = null
Branch.createBranchUniversalObject(properties).then(function (res) {
branchUniversalObj = res
//alert(JSON.stringify(res));
// optional fields
}).catch(function (err) {
alert('Error: ' + JSON.stringify(err))
})
let message = 'Check out this link'
Branch.initSession(function(data) {
if (data['+clicked_branch_link']) {
// read deep link data on click
alert('Deep Link Data: ' + JSON.stringify(data))
}
}).then(function(res) {
// create deep link
var analytics = {
channel: Date.now()
}
var properties = {}
branchUniversalObj.generateShortUrl(analytics, properties).then(function (res) {
alert('Response: ' + JSON.stringify(res.url))
}).catch(function (err) {
alert('Error: ' + JSON.stringify(err))
})
branchUniversalObj.onLinkShareResponse(function (res) {
alert('Goosebumps:' + JSON.stringify(res))
})
});
}
And I added the function to a button click. But, still it opens up the app home page when I click the created link.
It doesn't looks like you are using the correct setup for your deep link routing. Please reference this Branch documentation for best results: https://docs.branch.io/pages/deep-linking/routing/

Meteor facebook login - user is not show in SignIn space

I try to add Facebook login function on my app, it work but I have some problems
I start with:
meteor add accounts-password
meteor add accounts-ui
meteor add service-configuration
meteor add accounts-facebook
Then I write a test app on facebook, adding login and get my appId and secret
I copy documentation's code to configure settings (server side) and I put my appId and secret
ServiceConfiguration.configurations.upsert(
{ service: "facebook" },
{
service : "facebook",
appId: '123456789012345678',
secret: '123456789012345678123456789012345678123456789012345678',
loginStyle : "popup",
requestPermissions: ['email','user_friends']
}
);
I try to login with facebook and I have (showing in console.log) all the data I need (the picture is the picture profile in facebook), but the SignIn name is nto show in the top of the app
When I signin with a normal email password login I have no problem
The problem was in this function:
Accounts.onCreateUser(function(options, user) {
var imgAvatar = "/img/user.png";
var username = "NewPlayer_" + Math.floor(Math.random() * (9000 - 1000) + 1000);
if (user.hasOwnProperty('services') && user.services.hasOwnProperty('facebook') ) {
imgAvatar = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=small";
username = user.services.facebook.name;
}
return user;
});
I discover the correct way to use this function in this post
Accounts.onCreateUser((function(_this) {
return function(options, user) {
options = {
username: 'pippo'
}
return Object.assign({}, user, options);
};
})(this));

Backend service for ionic push

I have implemented ionic push notifications using pushwoosh. But there I use the dashboard which has provided by pushwoosh to send push notifications. I wanted to send push notifications using a back end which has created by my self. How do I do that?
i am working on ionic-framework and also using push notification to sent notification via REST API using node-gcm its working fine.
sample code
(function() {
function execute(rqst, q, fwk) {
var gcm = require('node-gcm');
var message = new gcm.Message();
message.timeToLive = 3000;
message.addData({
title: 'Push Notification Sample',
body: 'Abnormal data access',
icon: 'ic_launcher',
message: '"\u270C Peace, Love \u2764 and PhoneGap \u2706!'
});
message.addNotification({
title: 'Push Notification Sample',
body: 'Abnormal data access',
icon: 'ic_launcher',
message: 'hey , how are you?'
});
/* message.addData('message', "\u270C Peace, Love \u2764 and PhoneGap \u2706!");
message.addData('title', 'Push Notification Sample');
message.addData('msgcnt', '3');*/
// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
// Set up the sender with you API key
var sender = new gcm.Sender('xxxxxxxxxxxxxxxxx-hK5wE');
// Add the registration IDs of the devices you want to send to
var registrationIds = [];
registrationIds.push('APA91bEWB6-xcrfrfrffr-LqyMohLP4T-XuydQgt44Q6Acw5kmVDWvAaOsm1CriASm02SyBceZ2NBWF4FIES7grcPeY5v4fLQme2UqhRteeWRdD_Ma25QMGESOGAyw_Uhgg_EjkTl-');
// Send the message
// ... trying only once sendNoRetry
sender.send(message, {
registrationIds: registrationIds
}, function(err, result) {
if (err) {
console.error(err);
q.resolve({
status: 200,
data: {
data: err,
code: 1
}
});
} else {
console.log(result);
q.resolve({
status: 200,
data: result
});
}
});
}
return exports.execute = execute;
})();

Trying to retrieve facebook user email using facebook connect for cordova 3.2

I'm developing an android app wherein it requires to be logged into the app via facebook. I'm using facebook connect for cordova 3.2 and its working fine.But the problem is I'm not able to get the user's email address. I tried scope : email , permissions : 'email', but it simply does not work.I have installed facebook sdk for android the cordova 3.2 version and configured that with my project. I call the facebook login uri with a button click event.
var facebookConnect;
$("#facebookfbtn").unbind("click").click(function () {
facebookConnect.login(loginCallback, true);
});
document.addEventListener("deviceready", deviceready, false);
function deviceready(){
facebookConnect = window.plugins.facebookConnect;
}
loginCallback = function(result){
alert(result);
if(result == "OPENED")
{
facebookConnect.me(meCallback);
}
}
logoutCallback = function(result){
alert(result);
}
meCallback = function(result){
alert(JSON.stringify(result));
//var test = JSON.stringify(result);
alert('Good to see you, ' + result.name + '!' + '\n'+ 'Your Details :'+ '\n'+'Location:'+result.location+'\n'+'Email: '+result.email);
}
statusCallback = function(result){
alert(result);
}

phonegap - using external site as app - facebook login

I'm building a app site running through phone gap. Phone gap simply checks the user has internet connection and loads an external web app into the frame. I can navigat through the site fine with no blibs but as soon as I try the login to Facebook (either PHP redirect or javascript SDK) the app suddenly gets its navbar back or opens a new window (javascript SDK).
Is there anyway I can prevent this?
regards
It took some doing but using the ChildBrowser plugin, I've managed to login! (this is for android) I've used some code from a facebook connect plugin which didnt work for me, re wrote some stuffs so I could understand it and now works. Chears Juicy Scripter!
var fb_success = 'https://www.facebook.com/connect/login_success.html';
var fb_logout = 'https://www.facebook.com/connect/login_failed.html';
var fb_logout_ = 'http://m.facebook.com/logout.php?confirm=1&next=' + fb_logout;
var authorize_url = '';
var my_client_id = '##################';
var my_secret = '######################';
var my_type = 'user_agent';
var my_display = 'touch';
var token = false;
var fb_code = false;
var device_ready = false;
var ajax_url = '';
function logged_in(){
// alert('do what you need to do!');
}
function fb_force_logout(){
}
function fb_auth_check(){
console.log('fb_auth_check()');
if( fb_code !== false ) {
console.log('ajax test instigated...');
ajax_url = 'https://graph.facebook.com/oauth/access_token?client_id=' + encodeURIComponent(my_client_id) + '&client_secret=' + encodeURIComponent(my_secret) + '&code=' + encodeURIComponent(fb_code) + '&redirect_uri=' + fb_success;
$.ajax({
url: ajax_url,
type: 'POST',
success: function(html){
token = html.split("=")[1];
console.log('success! token = ' + token);
window.plugins.childBrowser.close();
fb_init();
},
error: function(error) {
console.log('there was an error...' + ajax_url);
window.plugins.childBrowser.close();
}
});
}
}
function fb_track_redirects(loc){
console.log('redirect tracked... ' + loc);
if ( loc.indexOf(fb_success) >= 0 || loc.indexOf(fb_success) > -1 ) {
fb_code = loc.match(/code=(.*)$/)[1]
console.log('success redirect... fb_code=' + fb_code);
fb_auth_check();
window.plugins.childBrowser.close();
} else if ( loc.indexOf(fb_logout) >= 0 || loc.indexOf(fb_logout) > -1 ) {
window.plugins.childBrowser.close();
}
}
function inner_init(){
console.log('inner_init()');
if( token === false ) {
console.log('token was false...');
authorize_url += "https://graph.facebook.com/oauth/authorize?";
authorize_url += "client_id=" + encodeURIComponent(my_client_id);
authorize_url += "&redirect_uri=" + encodeURIComponent(fb_success);
authorize_url += "&display=" + encodeURIComponent(my_display);
authorize_url += "&scope=publish_stream,offline_access";
console.log('instigated location change...');
window.plugins.childBrowser.onLocationChange = function(loc){
fb_track_redirects(loc);
}
console.log('open Facebbok login window');
window.plugins.childBrowser.showWebPage(authorize_url);
}else{
logged_in();
}
}
function fb_init(){
console.log('fb_init()');
if( device_ready === false ) {
console.log('first device run...');
document.addEventListener("deviceready", function(){
device_ready = true;
console.log('device ready...');
inner_init();
}, false);
}else{
inner_init();
}
}
$(document).ready(function(){
$('#login').bind('click', function(){
fb_init();
return false;
})
});
</script>
This is how it works for all apps native or web without patching the SDK code.
This is probably can be done, but will require digging into code. The question is do you really need it? This is a desired behavior.
You can try to use PhoneGap Facebook plugin and enable Single Sign On so native Facebook App if exists will be opened instead of browser to authenticate the user.
BTW,
Apps that are just external sites wrapped mostly rejected in app store.
Update:
Where is some points that may be also helpful in answer (by Facebook employee) to similar question How can I use an access token to circumvent FB.login().
Also have a look on ChildBrowser PhoneGap plugin (and Example).