Phonegap Facebook plugin not responding - ios

I'm trying to get the Phonegap Facebook plugin to work, but no errors occur and the plugin's login() function just doesn't do anything (it's being called, but doesn't do anything).
Whenever I try to install the plugin in the Cordova CLI, I get a Plugin already installed notice. I've added the plugin files manually, by adding FacebookConnectPlugin.h and FacebookConnectPlugin.m in the plugins folder. I've added the FacebookSDK.framework to the frameworks folder. However, when I open my app and tap on the login button (which correctly calls the function), nothing happens. The activity console in Xcode doesn't show any errors and no action is performed.
My JS code looks like this:
var login = function () {
if (!window.cordova) {
var appId = prompt("<MyAppId>", "");
facebookConnectPlugin.browserInit(appId);
}
facebookConnectPlugin.login( ["email"],
function (response) { alert(JSON.stringify(response)) },
function (response) { alert(JSON.stringify(response)) });
}
$('.login-btn').click(function() {
login();
});
What step am I missing to make this work? The plugin can be found here.
Also, when I start the app the activity console shows the following info:
2015-10-20 19:58:38.586 MyApp[5143:2355309] Apache Cordova native platform version 3.8.0 is starting.
2015-10-20 19:58:38.590 MyApp[5143:2355309] Multi-tasking -> Device: YES, App: YES
2015-10-20 19:58:38.595 MyApp[5143:2355309] Unlimited access to network resources
2015-10-20 19:58:39.033 MyApp[5143:2355309] Resetting plugins due to page load.
2015-10-20 19:58:39.711 MyApp[5143:2355309] Finished load of: file:///var/mobile/Containers/Bundle/Application/365E079A-56F7-4874-9914-182A57D6DFED/Qwest.app/www/index.html

Adding plugins manually in cordova usually leads to bad things, especially in the future if you ever want to update. For now I would try removing and adding the plugin:
cordova plugin rm phonegap-facebook-plugin
cordova plugin -d add -d plugin add /path/to/cloned/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"
(You did follow the instructions at https://github.com/Wizcorp/phonegap-facebook-plugin/blob/master/platforms/ios/README.md on how to install the plugin and cloned it to a different directory) See if that works, if not go with the more nuclear option of adding and removing the platform.
cordova platform rm ios
cordova platform add ios
This is sometimes required, but should only be performed if you have made no changes to the XCode project.
Also the plugin has been forked and https://github.com/jeduan/cordova-plugin-facebook4 which uses the Facebook4 SDK rather than Facebook3 SDK, as well it requires less fiddling to get the IOS plugin to work. It is api compatible so it should just work.

Related

Getting error while running the ionic cross platform project on xcode

I am new to ionic cross-platform while running the ionic cross platform app for generating build I am facing following error.
DiskCookieStorage changing policy from 2 to 0, cookie file:
file:///private/var/mobile/Containers/Data/Application/C234C014-5541-45C9-96A9-4D7B3E0AA4FA/Library/Cookies/Cookies.binarycookies
2016-10-15 14:55:26.568 HelloWorld[363:42830] Unbalanced calls to
begin/end appearance transitions for .
2016-10-15 14:55:26.591 HelloWorld[363:42906] [FATAL] [WL_INIT]
-[WLImpl initWL] in WLImpl.m:174 :: Init failure: Can't read checksum.js, The file name is invalid., (null). Reinstall the
application and try again.
I used MFP SDK(plugin)
So guys kindly give some suggestion for taking build
Its is just a helloworld program with MPF SDK.
Downloaded the sample project generated by ionic here with some bugs. bugs fixed code here.
Since the links you've provided are of no use (the links lack permission to download.....), I suggest that you will follow these blog posts:
Integrating MobileFirst Foundation 8.0 in Ionic-based apps
Best Practices for building AngularJS apps with MobileFirst Foundation 8.0
Here is the basic premise:
Install the following CLIs
npm install -g mfpdev-cli
npm install -g cordova ionic
npm install -g cordova
Create a New Ionic Project
ionic start myApp blank
Ionic automatically adds the Cordova iOS v3.8 plug-in, however MobileFirst Foundation v8.0 support Cordova iOS v4.0 and above. To overcome this, remove the iOS platform and re-add it. Change directory into your Ionic project and run:
ionic platform remove ios
ionic platform add ios#latest
If you want to add the android platform, you can add it with:
ionic platform add android#latest
Add the MobileFirst Cordova SDK
cordova plugin add cordova-plugin-mfp
You can confirm the installed plug-ins by entering ionic plugin list
Update Ionic Code
Open the js/app.js file.
The module is named starter.
angular.module('starter', ['ionic'])
The ng-app directive in the index.html file tells angular which code to run on the page.
To link the view and the model of the app together, create a controller in the app.js file.
.controller("mainCtrl", function($scope){
})
The $scope service allows you to share variables and functions from the controller to the view.
Go back to index.html.
Add ng-controller to the body tag and include the mainCtrl name. This allows you to use the controller anywhere inside the body tag.
ng-controller="mainCtrl"
Register App on MobileFirst Server
To enable the MobileFirst capabilities such as using the Mobile Browser Simulator to preview the application we need to add some JavaScript code to connect to the MobileFirst Server.
Open app.js and enter the following at the bottom:
function wlCommonInit() {
console.log(">> wlCommonInit() ..." );
var serverUrl = WL.App.getServerUrl(function(success){
console.log(success);
}, function(fail){
console.log(fail);
});
WLAuthorizationManager.obtainAccessToken().then(
function (accessToken) {
console.log(">> Success - Connected to MobileFirst Server");
},
function (error) {
console.log(">> Failed to connect to MobileFirst Server");
console.log(error);
}
);
};
Register your app with your MobileFirst Server.
mfpdev app register

ionic 2 error cordova not available

I am trying to use the cordova GooglePlus plugin in a new ionic 2 project (latest ionic2 version) but I always run into errors regarding cordova.
The plugin is properly installed and shows up in the plugin folder.
One approach I tried is this:
import { GooglePlus } from "ionic-native";
and then
GooglePlus.login().then(...)
The login method executes but always throws an error saying "cordova_not_available"
I want to test the app with ionic serve on my windows system first before deploying it to my android phone.
How can I make cordova available in the localhost server? From searching I understand that cordova.js is generated and always included in the deploy package for the device.
Another approach I tried is using
window.plugins.googleplus.login(...)
But this approach does not go through the typescript compiler who does not know anything about a plugins property on the windows object.
How can I fix this?
If you want the plugin to work for the browser you should add platform browser and run it:
ionic cordova platform add browser
and run it:
ionic cordova run browser
instead of ionic serve.
This error usually occurs when you're running the app in chrome using ionic serve which is normal as in the browser cordova native components are not there but also occur on emulator and devices when an ionic native plugin that you're using was nod added, even if you have added the ionic plugin for it.
For instance if you are using native Toast
then you need to add proper ionic dependencies:
ionic plugin add cordova-plugin-x-toast --save
but you also need to add cordova dependencies:
cordova plugin add cordova-plugin-x-toast --save
If you forget to add the later cordova plugin you'll get an error like:
Runtime Error Uncaught(in promise): cordova_not_available
Which can be tricky to find the cause.
Once you have added ionic and cordova dependencies you should be able to use it.
Make sure you import it:
import { Toast } from 'ionic-native';
inject Platform in constructor:
constructor(public navCtrl: NavController, private platform: Platform) {...
then use the native item:
this.platform.ready().then(() =>
Toast.show("Successfull", '5000', 'center')
.subscribe(
toast => {
console.log(toast);
}
));
Using ionic serve disables all the cordova plugins, because it is not running on a device.
Rather use ionic cordova run android
This will start an android emulator that should allow all the cordova plugins to function
I have also come across the second approach, but the syntax then has to be windows['plugins'].googleplus.login(...)
Sometimes using ionic cordova run browser is not the best option, since it takes a long time for it to compile your changes.
In my case, what was causing the issue was the FCM plugin. It cannot run on the browser, if I use ionic serve. Since my code was inside app.component.ts, it was easy for me to get around the problem. I simply used the following line:
if (platform.is('cordova'))
{ this.fcmx.onTokenRefresh().subscribe(token => {
this.pushNoti.storeNewToken(token); }); }
Using platform.is('cordova'), you can prevent the code causing trouble to run on the browser.
Simply Run after attaching android device
ionic cordova run android
make sure you correct google map key

How to make sure iOS Cordova Phone Gap version 5.2 plugins are installed and working

I am just trying to use the notifications plugin to start, I will need others later but having a problem getting it to work. When I try to use
navigator.notification.alert('test', myCallbackFn);
It says navigator.notification is undefined. my config file added this line when I added the plugin via CLI.
<plugin name="org.apache.cordova.dialogs" spec="~0.3.0" />
I am using this in the deviceReady function, where it looks like cordova.js is loaded without any problems.
Here is my whole snippet:
<script type="text/javascript">
document.addEventListener('deviceready', function onDeviceReady() {
angular.bootstrap(document, ['app']);
try{
//alert(navigator.notification);
navigator.notification.alert("test", function(){});
}catch(error){
alert(error);
};
}, false);
</script>
Also I did make sure to run this each time
$ cordova build ios
I don't use phonegap, I use cordova. The reason is, that phonegap uses older versions of cordova and you have less plugins in phonegap. The dialog plugin, which you are using, is v0.3 the current official version from Apache is v1.1.1.
To check, that the notification plugin is running, just use in your deviceready function:
console.log(navigator.notification);
Attention: Before you can use the console, you have to install the console plugin, found here: https://github.com/apache/cordova-plugin-dialogs
Do it with:
cordova plugin add cordova-plugin-console
But I suggest to restart the project and use cordova instead of phonegap, if you have an Apple machine.
Start from here and always use the edge version (select it in the top right corner):
http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface

Updating Cordova Plugin results in failed plugin

I'm running Cordova 3.4.1 and decided to update the one and only plugin I have, Console. I did based on the update to plugins dated April 23, 2014 ( http://cordova.apache.org/news/2014/04/23/plugins.release.html ).
Updating is done by first removing and then adding back the plugin. In other words:
cordova plugin rm org.apache.cordova.console
cordova plugin add org.apache.cordova.console
I then ran
cordova build
which does a lot of voodoo, after which I compiled and ran the app on iOS via Xcode.
The result is this fail: every time my code calls console.log I get this error in the XCode debugger output
CDVPlugin class CDVLogger (pluginName: Console) does not exist.
ERROR: Plugin 'Console' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
-[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
"INVALID",
"Console",
"logLevel",
[
"LOG",
"text i want to see"
]
]
Plainly the process of updating plugins is not working properly. How can fix this myself? And if I do will it effect any subsequent fix by the Cordova team?
FWIW: I repeated this process, tried an cordova platform update ios to no avail. I am loath to reinstall the entire thing given all the mysterious Xcode configuration and build stuff and hoping there's a simple fix...
I diff'ed the project against an earlier version I'd kept that worked properly and came up with this fix:
In Xcode, under your Phonegap or Cordova project, select
Target -> Build Phases -> Compile Sources
Add your plugin into the list there, in this case CVLogger.m located in your file structure under "Plugins".
After this, the project compiles without error and the console plugin works. No need to reinstall and reconfigure your entire project for this...

phonegap app crashes after installing plugin

After the fix i found for my previous issue: phonegap-cordova-3-4-clean-build-gets-apple-mach-linker-error
So now, if I make a blank project
$ cordova create hello com.example.hello HelloWorld
$ cordova platform add ios
$ cordova build ios
Now I need to do follow these instructions previous question
After that everything works fine.
BUT now I'm gonna install an plugin (doesn't matter what plugin).
For now i choose the logger (org.apache.cordova.console)
$ cordova plugin add org.apache.cordova.console
Now if i build and run the app. It crashes on startup.
see: screenshot
I enabled on Zombie Objects in xcode.
Even if I install previous versions of phonegap(cordova). I still need to do all these steps. Before I just create, add platform, build and run and it was done.
Nothing is working anymore, please helpe me out here. It's really annoying.
EDIT: If i comment the line console.log('Received Event: ' + id); in js/index.js the app will start, but if I call console.log it crashes.
objc_msgSend causes EXC_BAD_ACCESS with plugins on arm64
So i found why this happened:
I needed to replace in the fie ios/CordovaLib/Classes/CDVCommandQueue.m
objc_msgSend(obj, normalSelector, command);
in
((void (*)(id, SEL, id))objc_msgSend)(obj, normalSelector, command);
now everything works fine again.
source
I found something. If I build for ios. the js (console-via-logger.js) is doing the id wrong
screenshot
If I change
cordova.define("org.apache.cordova.console.console", function(require, exports, module) { /*
to
cordova.define("org.apache.cordova.console", function(require, exports, module) { /*
it works.
Has this something todo with me or cordova?
cordova -v: 3.4.0-0.1.3
npm -v: 1.4.5

Resources