Xcode PhoneGap navigator.connection Undefined - ios

Trying to port my PhoneGap javascript code into Xcode for debugging in iOS.
Using Cordova-3.0.0.
When I call:
navigator.connection.type
I am getting an 'undefined' for navigator.connection.
Did I not include the network connection plugin correctly in my config.xml, or is something else amiss? Yes, I included the correct cordova.js file specifically for iOS. Yes, deviceready has been fired.
Update: I am currently only running this on the iOS emulator.
My config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Hello Cordova</name>
<description>
Description
</description>
<author email="dev#callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<plugins>
<plugin name="NetworkStatus" value="CDVConnection" />
</plugins>
</widget>
Thank you for your help!

Been doing my research on this one, and finally came up with the solution.
Apparently PhoneGap (Adobe) recently updated their documentation, and filled in a lot of the holes I was running into for Phonegap 3.0.0
1) To do this using the command-line interface, you have to have git installed to be able to run those commands. Get git here.
2) They added to the Connection plugin documentation to use the following command-line interface commands to add the plugin to the project:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
$ cordova plugin rm org.apache.cordova.core.network-information
3) They updated the declaration in the config.xml file to the following (for iOS):
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>

If you simply want to know if you are connected or not try using navigator.onLine in your js instead. Works for me on IOS 8 & Android 2.3 and doesn't require any plugins

Related

Ship google-services.json with ionic package builds

Since I do not have Mac and iPhone, the only option for me is to use Ionic Cloud to build my native binaries. However, first I wanted to play with it and see how will it work with android builds.
My application uses https://github.com/fechanique/cordova-plugin-fcm
So I can build application with ionic cordova build android and run it on my emulator without any problems. However if I execute ionic package build android and then ionic package info I get message that my build FAILED.
Examine this failure with ionic package BUILD_ID I get this message:
Error: cordova-plugin-fcm: You have installed platform android but file 'google-services.json' was not found in your Cordova project root folder.
So, looks like that my google-services.json does not get uploaded to the cloud. So searching I find few posts of people that had same problem but none of them provided me with solution. I also found this:
https://cordova.apache.org/docs/en/latest/config_ref/index.html#resource-file
So I have tried to tell to ionic to include this google-services.json file with package like this:
<?xml version='1.0' encoding='utf-8'?>
<widget id="me.citybeep.partnerapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<!-- ... -->
<platform name="android">
<!-- ... -->
<resource-file src="google-services.json" target="platforms/android/google-services.json" />
</platform>
<!-- ... -->
<engine name="android" spec="^6.2.3" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-fcm" spec="^2.1.2" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="cordova-sqlite-storage" spec="^2.0.4" />
<plugin name="de.appplant.cordova.plugin.local-notification" spec="^0.8.5" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
</widget>
And also tried this:
<resource-file src="google-services.json" target="google-services.json" />
But we no success, however now I get another message:
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: me.citybeep.partnerapp
Name: City_Beep_Partner
Activity: MainActivity
Android target: android-25
Subproject Path: CordovaLib
Android project created with cordova-android#6.2.3
Error: Source path does not exist: google-services.json
I think this error is just that google-services.json did not get uploaded.
I am really dependent now on this plugin and using Ionic Push notifications is not an options at the moment...
So is there any way to tell ionic to include this google-services.json file when uploading to the cloud (and also .plist file). And I repeat, it is not problem with google-services.json file or my firebase project as everything works fine while performing build on my machine.
i tried several solutions, but the only one worked for me was specifying src and target with relative path of the google-services.json.
In your case change
<resource-file src="google-services.json" target="platforms/android/google-services.json" />
to
<resource-file src="platforms/android/google-services.json" target="platforms/android/google-services.json" />
this should work.

Cordova iOS Cross origin requests are only supported for HTTP

I'm building an iOS app and recently upgraded cordova-ios to 4.1.0 and started using: cordova-plugin-wkwebview-engine.
The problem is that now I get the error message Cross origin requests are only supported for HTTP while trying to load dependencies, so the app won't start.
It's trying to load systemjs dependencies over file://, but I included in my config.js.
I have no clue how to fix this. Does anyone have experience with this bevaviour?
cordova version: 6.1,0
cordova ios version: 4.1.0
related config.xml bit:
<access origin="*" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
Install this one plugin (cordova-ios 6+)
cordova plugin add https://github.com/globules-io/cordova-plugin-ios-xhr
then set
<preference name="AllowUntrustedCerts" value="true" />
<preference name="InterceptRemoteRequests" value="all" />
<preference name="allowFileAccessFromFileURLs" value="true" />
<preference name="allowUniversalAccessFromFileURLs" value="true" />
Install the following plugins:
cordova plugin add cordova-plugin-wkwebview-engine
cordova plugin add cordova-plugin-wkwebview-file-xhr
cordova plugin add https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix
Add to config.xml:
<platform name="ios">
...
<preference name="WKWebViewOnly" value="true"/>
...
</platform>
For Cordova iOS 6+ just need to install the following plugin.
cordova plugin add https://github.com/AraHovakimyan/cordova-plugin-wkwebviewxhrfix
This plugin does not depend on any other additional plugins and does not require additional permissions.
I had the same issue with my cordova project (actually Ionic v1) and I fix it with the following command:
cordova plugin add https://github.com/apache/cordova-plugins.git#wkwebview-engine-localhost
This will install a webserver that runs locally and the error should be gone after that. After you run that command, just run:
cordova prepare ios
or remove all plugins and reinstall:
rm -rf plugins/
cordova platform add ios
Make sure you have this in your config.xml:
<access origin="*" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
If you work with cordova-ios ^6.0.0. you need only to modify your config.xml file:
<platform name="ios">
...
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
...
</platform>
No need to install any additional plugins.
See Cordova iOS 6.0.0 Released for more info.
I had the same issue with my ionic v1 Cordova project. For me the solution was to migrate to capacitor, like this:
Start a New Ionic v1 project (% ionic start Bienchen blank --type ionic1)
Answer "yes" when the cli asked if to integrate "capacitor".
Checkout my Sources to the www-folder of the new Ionic v1 project
Build the project with capacitor (% ionic capacitor build iOS)
Keep in mind the the Cordova config.xml than is not longer used, instead configure in Xcode Project.

Custom Cordova iOS plugin

I'm new in developing with cordova and would like to add a custom written iOS plugin from file system. I use cordova version 4.3.0 with iOS version 3.8.0.
When trying to add the plugin with " $ cordova plugin add ../my_plugin_dir" I get the following error:
Error during processing of action! Attempting to revert...
Failed to install 'at.researchstudio.knowledgepulse.reminder':Error: Uh oh!
".../plugins/at.researchstudio.knowledgepulse.reminder/src/ios/Kpreminder.m" not found!
But the m-source file is in this folder!!! What am I doing wrong??
Plugin-Structure:
at.researchstudio.knowledgepulse.reminder/
plugin.xml
src/
ios/
Kpreminder.h
Kpreminder.m
www/
reminder.js
The plugin.xml looks like the following
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="at.researchstudio.knowledgepulse.reminder" version="0.0.1">
<name>Kpreminder</name>
<description>Reminder Functionalities for KP</description>
<keywords>KnowledgePulse reminder</keywords>
<js-module src="www/reminder.js" name="reminder">
<clobbers target="reminder" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Kpreminder">
<param name="ios-package" value="Kpreminder"/>
</feature>
</config-file>
<header-file src="src/ios/Kpreminder.h" />
<source-file src="src/ios/Kpreminder.m" />
</platform>
</plugin>
I think you may put you plugin in 'plugins'folder,put into other folder
like $project_folder/myplugins/at.researchstudio.knowledgepulse.reminder
then install it

Phonegap 3.6 iOS plugin not found

I know there are many topics handle this problem. But so far I was not able to understand why my own plugins are not getting called.
First of all:
I use phonegap 3.6.3, XCode 6.1, iOS 8.1 Beta
I am upgrading phonegap 2.9.0 to 3.6.3 with CLI. In 2.9.0 my Plugin 'Notification' worked just fine.
I read about upgrading from 2.x to 3.x and did all the stuff mentioned.
I added core plugins with CLI which (almost) all are working.
I read about adding plugins with CLI, but I don't have a git source, and I just want to put this plugin into xCode so that I can call it from js as CDVPlugin just as before in 2.9.0
My config.xml (in myApp/ folder) looks like:
<?xml version='1.0' encoding='utf-8'?>
<widget id="ch.itis.share" version="2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyApp</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<feature name="com.popup.test.plugins.Notification" required="true">
<param name="ios-package" value="Notification" />
</feature>
</widget
I have my Notification.h and Notifiaction.m class files inside myApp/Plugins folder and added them to the Build Phase in XCode.
I executed the command 'cordova prepare' to update the staging folder.
The staging config.xml has never the defined obove included!
When I call the plugin from js like:
Cordova.exec(
function(result){//do something},
function(error){//do something},
"com.popup.test.plugins.Notification",
"initDeviceNotification",
[]);
All I get from Phonegap is:
Plugin 'com.popup.test.plugins.Notification' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
I have many plugins like that. And nothing works anymore. Can anybody help?
UPDATE:
If I add the section manually to the staging config.xml it works. So how can I accomplish that the CLI prepare command will include my feature?

"PushPlugin not found" using Cordova 2.5 for iOS

I am using PushPlugin https://github.com/phonegap-build/PushPlugin and Cordova 2.5 for an iOS applicaiton.
In my Plugins folder I have these files:
Appdelegate+notification.h
Appdelegate+notification.m
PushPlugin.h
PushPlugin.m
In config.xml I have included the plugin like this:
<plugin name="PushPlugin" value="PushPlugin" />
I have also PushNotification.js in my www folder and included that in index.html.
When I run the application and execute the line in my push.js file:
pushNotification.register(this.tokenHandler,this.errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":app.onNotificationAPN"});
Then I get this error:
Error: Plugin 'PushPlugin' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml
Is PushPlugin compatible with Cordova 2.5?
I had this same issue when trying to get the pushplugin to work. I got it working by putting this block of code inside the config.xml (not the one in the www folder, but the one in the project folder)
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="PushPlugin">
<param name="ios-package" value="PushPlugin"/>
</feature>
</config-file>
<source-file src="src/ios/AppDelegate+notification.m" />
<source-file src="src/ios/PushPlugin.m" />
<header-file src="src/ios/AppDelegate+notification.h" />
<header-file src="src/ios/PushPlugin.h" />
</platform>
If you download the sample project from git, there's a file called plugin.xml that has a bunch of stuff that needs to be added to the xml (I think).
Hope that helps.

Resources