Phonegap Plugin not working (cordova-plugin-purchase) - javascript

My first Phonegap App. Everything working well except for plugins. I'm trying to install the cordova-plugin-purchase Plugin.
https://github.com/j3k0/cordova-plugin-purchase
I've followed the instructions. And when I run "phonegap plugins" in the console it shows the plugin as being installed.
According to the documentation, there is suppose to be a "store" object that I can reference. I set up the following code to test if it's working:
try {
store.register({
id: "my.reverse.item.example",
alias: "example name",
type: store.CONSUMABLE
});
} catch(err) {
alert(err);
}
On my real project, I have the real info in when registering the product, but I can't even get that far. In my TryCatch it returns the following alert:
"Can't find variable: store".
So it seems that the plugin isn't even installed correct. I'm not to phonegap plugins, so there's probably something very basic that I'm missing. Do I have to include a link to the plugin JS in my index.html file?

I ended up figuring out the problem. It seems to be that I didn't include the cordova.js file in my index.html. I don't see why I needed to do that since I've read over and over that you don't need to manually add the cordova files to your html files.
So the plugin works now and I can receive the store data that I setup using the cordova-plugin-purchase plugin tutorials.
Another thing to note once you actually have the plugin installed correctly:
The Bundle Identifier in Xcode needs to match the bundle ID for the In App purchases you are trying to connect to.

Related

require is not defined at npm.js:2

Forgive me if this is something simple as my research has come up empty in regards to this specific issue. I am using Bootstrap the most recent release. I have noticed that there is a file that is new from previous releases called npm.js. I am hosting all the Bootstrap files locally on my hosted web server. I call the file like all the others in the head to the full path to the file. In the console I have this error.
npm.js:2 Uncaught ReferenceError: require is not defined
at npm.js:2
Which is referring to this line.
require('../../js/transition.js')`
Which is from this npm.js file that is in the newest Bootstrap
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('../../js/transition.js')
require('../../js/alert.js')
require('../../js/button.js')
require('../../js/carousel.js')
require('../../js/collapse.js')
require('../../js/dropdown.js')
require('../../js/modal.js')
require('../../js/tooltip.js')
require('../../js/popover.js')
require('../../js/scrollspy.js')
require('../../js/tab.js')
require('../../js/affix.js')
I am unfamilar with this so I am not sure why I am getting this error but, how can I surpress this error and fix this issue? Do I even need this file? From what I understand if I am using modals or tooltips etc I need this. Is this correct?
You will need to download/config the missing libraries or requires. I am not sure which libraries you are using.
You can add the missing libraries to your package.json. Then call for npm install.

Excluding file from optimizing in Durandal build

I'm using Grunt to build the Durandal starter kit pro package.
It all works fine, except for one tiny detail. I would like to exclude one file (app-config below) from the optimizer and keep it as a non minified file when my build is done.
Based on other SO thread suggestions, I'm currently excluding it using empty:, which removes it from the optimized file as expected. However, when I open the built project I get an error in the console:
Uncaught Error: main missing app-config
options: {
name: '../lib/require/almond-custom',
baseUrl: requireConfig.baseUrl,
mainPath: 'app/main',
paths: mixIn({ }, requireConfig.paths, {
'almond': 'lib/require/almond-custom',
'app-config': 'empty:'
}),
optimize: 'none',
out: 'build/app/main.js',
preserveLicenseComments: false
}
Is almond the problem? I tried switching it to the full requirejs using include: ['path/to/require'], without success.
If you want to reproduce it locally you can either download the starter kit from the above link, or use a slightly configurated version which is closer to my example. Just run an npm install in the folder and you're all set.
I have downloaded you source code and do the following steps.
Extract zip file, open cmd and change the directory to this folder.
Run npm install to install all the dependencies.
Run grunt to start to build the project.
And when I open http://localhost:8999/ and saw the alert 1 which is alert(appConfig.foo); in your main.js.
After clicked Ok to hide the alert, the web page works fines. Any more input for you ?
So I am not sure how you are facing with this issue.
From the reference of the durandal issues found in this particular link
grunt-durandal
The main module controls the implementation of the durandal services
The link can be found in main.js
Here you can see the system.debug(true).You can remove it as written in the post here document.
The function as quoted in the article Overrides request execution timeout making it effectively infinite.
Also while using uglify in grunt the debug is set to false as per the documentation.
As per the documentation you need to set the system.debug(false)
Hope this might help a bit.
try:
....
paths: mixIn({ }, requireConfig.paths, {
'almond': ['lib/require/almond-custom', '!lib/require/almond-custom/app-config.js']
}),
....
just note the second path of app-config.js is correct. I think you should find your way, the above is a hint, if not a direct solution.

window.resolveLocalFileSystemURI is not a function

I created a web application that I need to convert to a mobile application, now all I have is html5/js/css files which means I don't have any www foder no platforms folder, not a cordova project ... I started first to build the app using cordova command lines, but I couldn't, I found many problems on that, I used then https://build.phonegap.com/ , and it works fine for me. In order to read the file, I have tried this code :
window.resolveLocalFileSystemURI("file:///android_asset/www/data/User.xml", function () {
alert("Success");
}, function () {
alert(" error ");
});
but, it didn't work. I added a try catch, the exception was :
window.resolveLocalFileSystemURI is not a function
Do i need to add something to my code to make it work ?
You need to install a plugin for this to work.
Basically, run "cordova plugin add org.apache.cordova.file" at your application's root directory.
For detailed instructions see here, under "Accessing the Feature":
http://docs.phonegap.com/en/edge/cordova_file_file.md.html#LocalFileSystem
UPDATE 2019
The correct way to add this plugin is now with this command in your project root:
cordova plugin add cordova-plugin-file
This is a core cordova plugin. Documentation found here on npm

Ember.js error "Cannot read property 'container' of undefined" when using Liquid Fire

I'm a beginner to front-end development and trying to utilize Ember.js for my project. I stumbled upon a great talk by Edward Faulkner about Liquid Fire at EmberConf 2015. It looked incredibly easy to apply and so I decided to give it a try.
My app is using Ember and Ember-Data Canary via ember-cli 0.2.0.
The structure of the app is somewhat like this:
application.hbs
\users
\user
work.hbs
profile.hbs
...
user.hbs
And the part of the router.js file that's responsible for this is:
this.resource('users', function (){
this.resource('users.user', { path: '/:user_id' }, function () {
this.route('work');
this.route('profile');
...
});
});
After I installed the addon with npm install --save-dev liquid-fire, I replaced {{outlet}} in my user.hbs file with {{liquid-outlet}} and added a transitions.js file with some simple transition data:
export default function () {
this.transition(
this.toRoute('users.user'),
this.use('fade')
);
}
But as soon as I navigate to the user page, I get a javascript error:
Uncaught TypeError: Cannot read property 'container' of undefined
Which originates in a liquid-outlet.js file, on line 15:
var View = this.container.lookupFactory("view:liquid-outlet");
I have no idea what I am doing wrong. It seems like there's something with my {{liquid-outlet}} being placed in the wrong place or something, but I've tried moving it elsewhere, with no luck. As soon as I navigate to a template that has {{liquid-outlet}} in it, I get the same error. Please help.
Thank you,
Oleg
This issue has been fixed in liquid fire's master branch. You can get a working build for now by pulling from git with:
npm install ef4/liquid-fire --save-dev
The next release will of course also include the fix.
Check this github issue thread for updates: https://github.com/ef4/liquid-fire/issues/190

Sencha Cmd unable to parse custom code in app.js

For some reason, Sencha Cmd fails when it parses app.js with custom code. Below, is a snippet from an application I'm deploying to testing (unminified JavaScript but in a single file) or to production (minified JavaScript).
The browser throws the following JavaScript exceptions from the deployed folder (with all-classes.js):
(note: the folder with all js source code runs fine)
GET http://localhost/App/App/model/app/CheckTreeNode.js?_dc=1396967410158 404 (Not Found) all-classes.js:10841
GET http://localhost/App/App/store/app/UserPreferenceNodes.js?_dc=1396967410159 404 (Not Found) all-classes.js:10841
GET http://localhost/App/app/controller/ViewportAdmin.js?_dc=1396967410177 404 (Not Found) all-classes.js:10841
...
Uncaught Error: [Ext.Loader] Failed loading 'App/model/app/CheckTreeNode.js', please verify that the file exists all-classes.js:11259
Uncaught Error: [Ext.Loader] Failed loading 'App/store/app/UserPreferenceNodes.js', please verify that the file exists all-classes.js:11259
Uncaught Error: [Ext.Loader] Failed loading 'app/controller/ViewportAdmin.js', please verify that the file exists
I tried fixing things by adding a "requires" config in my Ext.application class, but that didn't help. How can I force these files to be seen by Sencha Cmd? Sencha Touch has a solution by allowing you to add files to "app.json". Perhaps there is a similar solution for ExtJS applications that I'm unaware of?
If there are more elegant solutions, I'm open to them. I needed the user preferences in the constructor of a bunch of my classes, so this was the only place I could get it to load and be ready when those are called. If there is a different way to load data that can be available when building classes within MVC, I'm fine with a different solution for that. As for having two viewports, this is what I found to work, so that's what ViewportAdmin is. Just a second viewport.
app.js source code:
Ext.application({
name: 'App',
extend: 'App.Application',
requires: [
'App.store.app.UserPreferences',
'App.view.ViewportAdmin'
],
autoCreateViewport: false,
launch: function () {
Ext.StoreManager.lookup('App.store.app.UserPreferences').on('load', function () {
if (window.location.href.indexOf('/App/index.aspx?admin=true') > -1) {
Ext.create('App.view.ViewportAdmin');
}
else if (window.location.href.indexOf('/App/index.aspx') > -1) {
Ext.create('App.view.Viewport');
}
});
}
});
The problem wasn't due to what I suspected. After deploying the app to testing (ran command "sencha app build testing", I put a breakpoint on the two lines of code below. It turns out that the controller that it errored on had the store which was not being used. It failed because of that. The CheckTreeNodes.js was the model being used in that store. I just removed it from the stores list to resolve it.
code in all-classes.js (generated from YUI compressor I think):
script.src = url;
(Loader.documentHead || document.getElementsByTagName('head')[0]).appendChild(script);
I looked at the call stack in Google Chrome and found that the anonymous function call (in the call stack) was showing the list of stores from the ViewportAdmin controller.

Categories

Resources