PhoneGap + WP7: how to use a plugin - plugins

How do I integrate a plugin with PhoneGap on Windows Phone 7?
I've found tutorials for iOS, Android and BlackBerry, but nothing about WP7.
I've put the .cs file in the Plugins folder, but I'm not sure it is enough.

To integrate a wp7 plugin with phonegap these are the general steps :
Include the plugin definition and js implementation javascrtip file in your html page head section
[script type="text/javascript" charset="utf-8" src="myPlugin.js"][/script]
in your code you need to call it like:
navigator.plugins.myPluginName.myPluginFunction(parameters);
you may need to make few additions in your html as per plugin required.
Also check for entry for myplugin in WMAppManifest.xml
I have used myPlugin as an reference so please replace the name with your actual plugin name.
Hope this help you
~K

The problem was in the .js file.
PhoneGap is now called Cordova, so the js files of old plugins have to be updated with the new class name.

Related

How do i make working custom css in ionic?

I've added custom css in ionic+angular which is working absolutely perfect with browser and its devices, but while i am generating apk for android device custom css is not working in android.
I am running this command to generate APK : ionic cordova run android
For more information i attached ionic version and index html screenshot.
version screenshot
Index.Html screenshot
First, make sure that "appStyle.css" file is written with S uppercase. Windows machines are case insensitive and Linux Machines (Android) are case sensitive.
Second, make sure that you're changing the index.html at src folder, not at www. Because www is the generated files and it is rewritten every build.
At last, as Abdul said in the comment, you should import your CSS files at app/app.scss.
#import '../assets/css/font-awesome.min';
I recommend you to put the css files outside from assets, which is recommended only static files, like images.

javascript library not loaded in ionic

Im including the google cast external javascript library. When I run with ionic serve it works good, but when I run the app in the phone, the library is not loaded. Debugging can see that :
https://cdn-enterprise.discourse.org/ionicframework/uploads/default/original/3X/a/d/ad4c985f45c1c538bdfbfbb02d10141b6929e1d5.png
The "http" is replaced by "file"!
I tried to include the libraries with that code:
script src="//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1">
and with type="text/javascript" added; but all codes replaces http by file, and the library is not loaded.
Any suggestions?
When you run the app do not add cdn files starting with "//:", add them like "http://".
If its possible download those files and keep them in directory, after that give directory path to file.
e.g. <script type="text/javascript" src="assets/js/library.js">

Obfuscation in Ext Js 4.2 with Sencha CMD 3

I just installed all the required tools for the new Sencha Cmd(Ruby, Compass, Ext Js 4.2 SDK) everything works fine, but I don't know how to obtain the unique obfuscated file from the .js sources in my Ext Js application.
Any help, please? Thanks in advance.
I tried the "sencha app build" command from all the folders in my application path, always get the "Please ensure this command was executed from a valid application directory. Unable to locate 'app.dir' config property from 'sencha.cfg'
After more reading about the subject I think before the "sencha app build" command to work I need to generate the bootstrap.js file manually because my application wasn't generated using the framework, but I'm stuck here also. Anyone ever did that? Please?
The best way to get things work if your have legacy project (when project structure is not generated by sencha cmd tool) is to generate empty project and the move all necessary files/folders in to your existing project and try to adjust all configurations. You will need to move:
.sencha folder
folder with extjs development classes
bootstrap.js, bootsrap.css, build.xml
modify you start page correspondingly (index.html, index.jsp, or whatever)
create application.js to start your application
bootstrap files are always generated automatically. To generate it normally you have to use sencha app refresh command.
Basically the most important changes have to be made in .sencha folder. Most of the config files in this folder have a lot of comments so this is not a problem to understand what to change. Also it's good idea to refer official doc page: Sencha CMD

cordova 1.7.0 set info error

I am using cordova 1.7.0. My app is running fine in simulator but a message comes like
Error: executing module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you included the iOS version of the cordova-1.7.0.js file?
I have included
<script type="text/javascript" charset="utf8" src="[location of cordova.ios(for ios)]"></script>
in index.html but did not work.Plz help.
there must be something wrong with the path to the js.
The index.html file is read?
Is your www folder maybe a group instead of a reference folder?
Go step by step
This generally happens when the cordova file is not properly available when the page is loaded. You can check that it is referencing properly by opening the index.html (or your start page) in the Chrome and check in Inspect Element that all the resources are loaded and there are no errors.
to solve this problem, just follow steps in picture

Location permission alert on iPhone with PhoneGap

How do you change the string on the alert saying:
(Appname/whatever it is) would like to use your current location
Of course, I only want to change the appname part. Because when you use the PhoneGap framework, the string is very ugly, something like this:
/var/mobile/Applications/157EB70D-4AA7-826E-690F0CBE0F/appname.app/www/index.html
Someone having an idea?
You need to do the geolocation after the device is ready. The following Jquery code, for example, will geolocate without that nasty alert:
$(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position) {
// your callback here
}
function onError(error) {
// your callback here
}
On phonegap 3.0 the answer by Pius Uzamere needs to be followed AND the plugin installed.
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
otherwise you will get the double permission request.
I just followed the documentation and solved it.
Open the terminal and cd to your project and enter following command.
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Also add this in your config.xml
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
It will solve this issue. :)
Source: http://docs.phonegap.com/en/3.0.0/cordova_geolocation_geolocation.md.html#The%20Command-line%0AInterface
Although this question is much older, I found similar questions here and here.
For my resolution, I had to add NSLocationWhenInUseUsageDescription to the .plist file. However, I suppose since my geolocation plugin was out of date, I had to update it first. Then I had to remove/add the Cordova iOS platform. Finally, I added NSLocationWhenInUseUsageDescription to the .plist file.
First, remove/add the geolocation plugin:
cordova plugin rm org.apache.cordova.geolocation
cordova plugin add org.apache.cordova.geolocation
Second, remove/add the iOS platform:
cordova platform rm ios
cordova platform add ios
Last, add NSLocationWhenInUseUsageDescription to the .plist. Open /platforms/ios/{project}/{project}-Info.plist and add the following:
<key>NSLocationWhenInUseUsageDescription</key>
<string>[App Name] would like to access your location when running and displayed.</string>
See this iOS Developer Library link for detailed information regarding NSLocationWhenInUseUsageDescription versus NSLocationAlwaysUsageDescription versus NSLocationUsageDescription.
Finally fixed the issue.
IN the index.html just move your cordova.js up
<script src="cordova.js"></script>
as the first js file to be included (especially make sure it is above maps include js). This will make sure that the prompt shows only once.
No other codejs or ondeviceready is needed.
After looking for solution i've founded, just add a variable when you add the plugin location like this line
cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="your usage message"
None of the above answers worked for me. My location request was already firing on deviceready. Adding the following to config.xml fixed the issue:
<gap:plugin name="org.apache.cordova.core.geolocation" />
To solve the issue I have to run cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git which adds (automatically) to the config.xml the following:
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
To get things working I have to put also this lines into the config.xml:
<plugins>
<plugin name="Device" value="CDVDevice" />
<plugin name="Logger" value="CDVLogger" />
<plugin name="Compass" value="CDVLocation" />
<plugin name="NetworkStatus" value="CDVConnection" />
<plugin name="Debug Console" value="CDVDebugConsole" />
<plugin name="Geolocation" value="CDVLocation" />
<plugin name="SplashScreen" value="CDVSplashScreen" />
<plugin name="Battery" value="CDVBattery" />
<plugin name="Globalization" value="CDVGlobalization" />
</plugins>
Hope it could be helpful.
After making sure my geolocation request was called after the device was ready, making sure the geolocation plugin is correctly installed and configured, I was still receiving the unsightly popup.
I resolved it by moving and referencing my cordova.js file and cordova_plugins.js files into the root directory of my application (they were originally in a subfolder), so the path to cordova.js would be:
<script src="cordova.js"></script>
I feel this should be included in the documentation (maybe it is, but I haven't managed to find it)
Just by including "cordova.js" file in your html file where you are accessing this location will resolve this issue. NOTHING FANCY REQUIRED.
1) modify Location.m in PhoneGapLib project. replace all references of
navigator.geolocation with navigator_geo
2) Copy phonegap.js to phonegap2.js and put in root of app. I have now
learned that every time I build my application and load it onto device
or simulator, the phonegap.js file is being regenerated. OK. Well I
need to modify it so lets just use another one and deal with the
hassles of upgrading in the future.
3) Modify the line (in phonegap2.js) that creates the constructor for
the navigator.geolocation on 626 to be ... if (typeof navigator._geo
== "undefined") navigator._geo = new Geolocation();
4) Now in your HTML whenever you want to use the PHONEGAP GPS stuff,
you can reference it with navigator._geo.getCurrentPosition or similar
5) Enjoy the ONE, and CLEAN, location alert permission without
revealing to your users your intelligence to use PhoneGap and build an
app with HTML/JS.
* CAVEAT AND PLEASE HELP! *
If I run the watchPosition function, I will get the first location
update with all sorts of stats. There after, It will always report an
error. I assume this sucks for this 30 second time of getting accurate
GPS on these things?
http://groups.google.com/group/phonegap/browse_thread/thread/8067c2037816a9ad
I followed all the instructions and it still failed. In the end I played around with the PhoneGap demo and found the final solution:
Move all the js files and html files into the same folder (not even sub-folder). Congratulations! Problem solved, no permission alert any more : )
BTW, You'd better use a " setTimeout(function(){utility.getGeoData();},1000);" I found "document.addEventListener("deviceready", utility.getGeoData(), false);" not work for me.
Hope that helps when you find no solution above : )
Good luck!
Since I was struggling for days now with the same problem and finally found the solution, I decided to share it with anyone who still was not able to fix it.
The solution is simple: The geolocation plugin was missing in the plugins directory within the www directory, even though I added the plugin via the phonegap command line interface AND the plugin files were in the /Plugins directory. So you only have to copy the missing files into /www/plugins and you are done. Just simple as that.
If anyone needs the missing files: http://d.pr/f/xqhq
btw: i am using cordova 3.2.0.
I hope this works for you as well!
Phoengap/Cordova version 3.5 here.
Similar to Manuel's answer above but this time the plugin does not install in the platforms/ios/[appname]/Plugins folder.
The fix for me was to just manually create a new folder for the plugin in the ../platforms/ios/[appname]/Plugins folder > then rename it to org.apache.cordova.geolocation > then copy the .h and .m files of the plugin into it.
You can find the .m and .h files for the geoLocation plugin in the [root]/plugins/org.apache.cordova.geolocation/src/ios directory.
Got this error (and a lot of others) after upgrading Cordova from 3.6 to 4.3.
I think there is some fails in the upgrade process and the only working solution for me was cordova platform rm ios then cordova platform add ios
/!\ You will lost all your ios project settings and you need to reupload splash and icons.
In my case, I am using Cordova/Ionic and have experienced the same problem. That's because of the code before device is ready. I have simply wrapped the code with document.addEventListener on "deviceready". For example:
document.addEventListener("deviceready", function () {
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
...your code here...
});
});
Then the additional message does not appear.
I'm late to the party here, but will answer the question for reference.
The answer is to use the geolocation functions found in phonegap.js which is included with Phonegap. You will be able to find such instructions on the Phonegap site at http://www.phonegap.com.
If you use navigator.geolocation, you are using the default Safari geolocation system. This happens as PhoneGap works by running your pages effectively in a Safari instance. If you include phonegap.js into your site, you can use a separate geolocation method exposed by PhoneGap's Objective-C code, which will present the behaviour seen in other apps where it asks for permission from [your app name].
"Move all the js files and html files into the same folder (not even sub-folder). Congratulations! Problem solved, no permission alert any more : )" Like Caleb says works for me, well only moving the cordova.js file to the root and adding the plugin to config.xml
What is the Bundle display name of your project?
Try changing manually from the default value ${PRODUCT_NAME} and see..
That Permission to use location alert picks your bundle display name only!!