I have followed the phonegap integration of Urban Airship from their website, but for some reason I am getting errors
here is my xcode error log
2015-06-15 11:08:32.104 TubrTest[73807:2760310] Apache Cordova native platform version 3.8.0 is starting.
2015-06-15 11:08:32.104 TubrTest[73807:2760310] Multi-tasking -> Device: YES, App: YES
2015-06-15 11:08:32.107 TubrTest[73807:2760310] Unlimited access to network resources
2015-06-15 11:08:32.108 TubrTest[73807:2760310]
Started backup to iCloud! Please be careful.
Your application might be rejected by Apple if you store too much data.
For more information please read "iOS Data Storage Guidelines" at:
https://developer.apple.com/icloud/documentation/data-storage/
To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file
2015-06-15 11:08:32.207 TubrTest[73807:2760310] [CDVTimer][statusbar] 17.539978ms
2015-06-15 11:08:32.207 TubrTest[73807:2760310] [CDVTimer][localnotification] 0.038981ms
2015-06-15 11:08:32.207 TubrTest[73807:2760310] [CDVTimer][localnotification] 0.003994ms
2015-06-15 11:08:32.214 TubrTest[73807:2760310] [CDVTimer][file] 7.194996ms
2015-06-15 11:08:32.227 TubrTest[73807:2760310] [CDVTimer][splashscreen] 12.713015ms
2015-06-15 11:08:32.227 TubrTest[73807:2760310] [W] -[UAConfig validate] [Line 170] Development App Secret is not valid.
2015-06-15 11:08:32.228 TubrTest[73807:2760310] [E] -[UAConfig validate] [Line 187] Current App Secret (dBWt4mUaR2K5xiTthy92pgt) is not valid.
2015-06-15 11:08:32.228 TubrTest[73807:2760310] [E] +[UAirship executeUnsafeTakeOff:] [Line 169] The AirshipConfig.plist file is missing and no application credentials were specified at runtime.
2015-06-15 11:08:32.229 TubrTest[73807:2760310] [CDVTimer][uairship] 1.401007ms
2015-06-15 11:08:32.229 TubrTest[73807:2760310] [CDVTimer][TotalPluginStartup] 39.427996ms
2015-06-15 11:08:32.294 TubrTest[73807:2760310] [E] __52+[UAirship handleAppDidFinishLaunchingNotification:]_block_invoke [Line 296] [UAirship takeOff] was not called in application:didFinishLaunchingWithOptions:
2015-06-15 11:08:32.294 TubrTest[73807:2760310] [E] __52+[UAirship handleAppDidFinishLaunchingNotification:]_block_invoke [Line 297] Please ensure that [UAirship takeOff] is called synchronously before application:didFinishLaunchingWithOptions: returns
2015-06-15 11:08:32.319 TubrTest[73807:2760310] Resetting plugins due to page load.
2015-06-15 11:08:33.227 TubrTest[73807:2760310] THREAD WARNING: ['DFPPlugin'] took '55.412109' ms. Plugin should use a background thread.
2015-06-15 11:08:33.228 TubrTest[73807:2760310] <Google> To get test ads on this device, call: request.testDevices = #[ GAD_SIMULATOR_ID ];
2015-06-15 11:08:33.361 TubrTest[73807:2760310] THREAD WARNING: ['DFPPlugin'] took '133.538086' ms. Plugin should use a background thread.
2015-06-15 11:08:33.810 TubrTest[73807:2760310] <Google:HTML> You are currently using version 6.8.0 of the SDK. Please consider updating your SDK to the most recent sdk version to get the latest features and bug fixes. The latest SDK can be downloaded from http://goo.gl/iGzfsP. A full list of release notes is available at https://developers.google.com/mobile-ads-sdk/docs/admob/ios/rel-notes.
2015-06-15 11:08:34.094 TubrTest[73807:2760310] adViewDidReceiveAd
2015-06-15 11:08:37.441 TubrTest[73807:2760310] Finished load of: http://192.168.1.65:9000/
here is the javascript I am running on device ready
document.addEventListener('deviceready', function(evt) {
//Urban airship code
// Register for any Urban Airship events
document.addEventListener("urbanairship.registration", function (event) {
if (event.error) {
console.log('There was an error registering for push notifications');
} else {
console.log("Registered with ID: " + event.channelID);
}
});
document.addEventListener("urbanairship.push", function (event) {
console.log("Incoming push: " + event.message);
});
// Set tags on a device, that you can push to
UAirship.setTags(["loves_cats", "shops_for_games"], function () {
UAirship.getTags(function (tags) {
tags.forEach(function (tag) {
console.log("Tag: " + tag);
});
});
});
// Set an alias, this lets you tie a device to a user in your system
UAirship.setAlias("TubrUser", function () {
UAirship.getAlias(function (alias) {
console.log("The user formerly known as " + alias);
});
});
// Enable user notifications (will prompt the user to accept push notifications)
UAirship.setUserNotificationsEnabled(true, function (enabled) {
console.log("User notifications are enabled! Fire away!");
});
});
here is my config settings
<!-- Urban Airship app credentials -->
<preference name="com.urbanairship.production_app_key" value="mykey" />
<preference name="com.urbanairship.production_app_secret" value="mykey" />
<preference name="com.urbanairship.development_app_key" value="mykey" />
<preference name="com.urbanairship.development_app_secret" value="mykey" />
<!-- Required for Android. -->
<preference name="com.urbanairship.gcm_sender" value="Your GCM Sender ID" />
<!-- If the app is in production or not -->
<preference name="com.urbanairship.in_production" value="true" />
<!-- Optional config values -->
<!-- Enable push when the application launches -->
<preference name="com.urbanairship.enable_push_onlaunch" value="false" />
<!-- Override the Android notification icon -->
<preference name="com.urbanairship.notification_icon" value="ic_notification" />
<!-- Specify the notification accent color for Android API 21+ (Lollipop) -->
<preference name="com.urbanairship.notification_accent_color" value="#0000ff" />
<!-- Clear the iOS badge on launch -->
<preference name="com.urbanairship.clear_badge_onlaunch" value="true" />
Related
I am using cordova-plugin-purchase (https://github.com/j3k0/cordova-plugin-purchase) in a Cordova (Ionic 4) app, which works on Android no problems. When I try to test a purchase on iOS, the app crashes with unexplained message below.
The app is also unable to retrieve product details from the store. I mention that the app is not yet released and it's currently in TestFlight.
This is the output log via Xcode:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SKProduct localizedPrice]: unrecognized selector sent to instance 0x28191ca40'
This is how I try to get the product details (crashes with output above)
this.store.get("coin_pack_1");
And this is how I try to initiate a purchase (crashes with output above)
let productId = "coin_pack_1";
let iapOptions: IAPProductOptions = {
id: productId,
alias: productId,
type: this.store.CONSUMABLE
};
this.store.register(iapOptions);
this.store.verbosity = this.store.DEBUG;
let product: IAPProduct = this.store.get(productId);
// register handlers
this.store.once(productId).approved((data: IAPProduct) => {
// Fired when a purchase has been approved by the store
console.log("approved, ", data);
product.finish();
resolve(true);
});
this.store.refresh();
I have now switched (forced) to WKWebView as UIWebView was not allowed anymore on App Store, which somehow solved the issue.
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
I'm trying to read a function from an iOS framework i have created which I have added into a custom cordova plugin.
I have compiled the framework as "Generic iOS Device", as was suggested in some post but i still have a problem in using the framework function..
I'm working with cordova cli 7.0.1 and cordova-ios": ^4.4.0.
in the plugin config.xml file I'm using
which add my framework but calling my function (in the plugin which try to read a framework function) return:
error: 'printer' is unavailable: cannot find Swift declaration for this class:
let printtt = testtest.printer();
^~~~~~~
testtest.printer:2:12: note: 'printer' has been explicitly marked unavailable here
open class printer : NSObject {
^
/platforms/ios/MyApp/Plugins/com-moduscreate-plugins-echo/ModusEchoSwift.swift:11:5:
error: value of type 'printer' has no member 'printlocal'
printtt.printlocal();
^~~~~~~ ~~~~~~~~~~
** BUILD FAILED **
does any one have encountered such a problem?
PS. my framework contains a public class printer with public method
printlocal which i have tested under xcode 8.xx
**my plugin.xml file:**
<?xml version='1.0' encoding='utf-8'?>
<plugin id="com-moduscreate-plugins-echo" version="0.0.1"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>ModusEcho</name>
<js-module name="ModusEcho" src="www/ModusEcho.js">
<clobbers target="modusEcho" />
</js-module>
<platform name="ios">
<framework src="src/ios/testtest.framework" custom="true" embed="true" />
<config-file target="config.xml" parent="/*">
<feature name="ModusEcho">
<param name="ios-package" value="ModusEchoSwift" />
</feature>
</config-file>
<source-file src="src/ios/ModusEchoSwift.swift" />
</platform>
</plugin>
my swift file:
import testtest
#objc(ModusEchoSwift) class ModusEchoSwift : CDVPlugin{
#objc(echocrypt:)
func echocrypt(command: CDVInvokedUrlCommand) {
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
let printtt = testtest.printer();
printtt.printlocal();
}
}
**my dynamic framework class:**
import Foundation
public class printer:NSObject {
public func printlocal() {
print("from printer!!!");
}
}
www/modusecoh.js file:
var exec = require('cordova/exec');
exports.echocrypt = function(arg0, success, error) {
exec(success, error, "ModusEcho", "echocrypt"`enter code here`, [arg0]);
};
Found the problem:
Since i have used "cordova-plugin-add-swift-support" plugin, it has set the ios min deployment target of the project to 7.0 hence the frameworks (dynamic library), were introduced only from 8.0
when changing the plugin IOS_MIN_DEPLOYMENT_TARGET global var value to 8.0, (after recompile), it has started working!
so, the above code is the way of working with a xcode framework written in swift3 from cordova custom plugin.
I've been using the cordova-plugin-inappbrowser plugin for a long time now and when I updated the software to 10.2.1 on my apple test devices the plugin no longs works properly. When I try to open the inappbrowser link nothings happens unless I click the home button and return to the app. This happens for the simulators as well as on real devices like ipad, iphone 5s, iphone 6 and iphone 7. it works fine on android devices just not the latest iOS.
Here's a list of everything i tried:
updated inappbrowser to latest version - 1.7.1
removed and reinstalled the plugin and ios platform
tried making a blank app with the inappbrowser plugin
tried changing the index.html meta tag to include gap:
<meta http-equiv="Content-Security-Policy" content="default-src * 'self' gap: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *; child-src 'self' 'unsafe-inline' *;">
I can't seem to find anything else to try as most posts I do find that have a similar issue haven't been answered.
Below is the relevant code to how the inappbrowser plugin was installed and is being used:
config.xml Structure
<widget>
<content src="index.html"/>
<access origin="*"/>
<allow-navigation href="*"/>
<preference/>
...
<feature name="StatusBar">
...
</feature>
<platform name="ios">
... icons and splash ...
</platform>
<plugin name="cordova-plugin-inappbrowser" spec="~1.7.1"/>
</widget>
Using plugin in Controller
$scope.showLink = function(url){
var options = {
location: 'yes'
}
$cordovaInAppBrowser.open(url, '_blank', options)
.then(function(event){
// success
console.log('inappbrowser', event);
})
.catch (function(event) {
// error
console.log('inappbrowser error', event);
});
};
$scope.openUrl = function(url) {
window.open(url, '_blank', 'location=no');
};
I'm using ionic v1.7.14 , cordova: 6.2.0 and xcode 8
As suggested by CodeGems, in the comments, adding gap://ready to your Content-Security-Policy should fix the issue.
I have been experiencing the same issue, and have tried in the past 2 weeks numerous solutions found online for this with no success, any help appreciated :)
I am writing a simple app using Cordova for IOS and Android and building it using Phonegap build. The problem is that I cannot get the "navigator.geolocation.getCurrentPosition" (or navigator.geolocation.watchPosition) calls to return anything except a timeout error on iOS. (works perfectly on Android)
Additionally, the location services dialog never appears (requesting user permission to allow GPS for the app)
To add to this strange behavior, it seems that i have to touch the screen after the app is loaded to initiate the geolocation call, on most cases the app just sits there and does nothing until the screen is touched.
Testing this on iPhone 5 with iOS 9
Things I tried:
Changing timeout settings (up to 30 seconds)
Setting enableHighAccuracy true/false
Running code with or without the geolocation plugin
Manually adding the NSLocationWhenInUseUsageDescription/NSLocationAlwaysUsageDescription settings (or both) to the plist file
Installing different plugin versions for the geolocation plugin
Changing Content Security Policy meta tag
Trying to add or remove the <plugin> declaration from root config.xml
Current plugins installed ($cordova plugin list):
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-geolocation 1.0.1 "Geolocation"
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova.plugins.diagnostic 2.3.5 "Diagnostic"
Root config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="info.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>App name</name>
<description>
App Name
</description>
<author email="test#test.com" href="http://test.com">
App Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
index.js
var geo = {
getGeo: function() {
navigator.geolocation.getCurrentPosition(
geo.onSuccess,
geo.onError,
{maximumAge:0, timeout: 5000, enableHighAccuracy: false});
},
onSuccess: function(position) {
alert('GOT location');
alert(position.coords.latitude + ' --- ' + position.coords.longitude);
},
onError: function(error) {
alert('error getting geo!');
}
};
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
geo.getGeo();
}
};
app.initialize();
iOS Plist file:
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires constant access to your location in order to track your position, even when the screen is off.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string/>
Index.html:
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
Any help in the right direction appreciated!
#daddio
Oh. that's it. I should be more dogmatic on this. This should take care of the problem.
It is not advisable to use Phonegap CLI to make your Phonegap Build build project. Phonegap build requires that index.html and config.xml both sit in the root directory. All the extra files that you are required to use with Phonegap CLI, never are created or needed with Phonegap Build.
So, I'm going to give you one of my working demos. Notice that all the files are in one (1) directory.
tutorial/blog entry - An HTML Boilerplate for Phonegap Build
source code Phonegap--Generic-Boilerplate
Notice how the compiler version is set to:
<preference name="phonegap-version" value="cli-5.2.0" />
Notice, if you change cli-5.2.0 to 3.7.0, nothing appears to change.
Basically for Phonegap Build, you need index.html and config.xml - that's it. Then for security reasons (as of Cordova Tools 5.0.0), it is advisable to create a css file and a javascript file. However, I'll show you how to get around this.
Here is my complete list of Demo Apps.
Phonegap Demo Apps
YOUR FIX
This is my working code, test with 3.5.0 and cli-5.1.1 and cli5.2.0
source code Phonegap-GPS-Test
On Your fix, notice how the version is set to: <preference name="phonegap-version" value="3.5.0" />
Okay, I trust all of this will work for you. As such, your documentation is here:
https://build.phonegap.com/docs
There are some special rules for adding plugins, but I'll give you those when your program is running.
How to add Plugins with Phonegap Build
FOR THE MOST IMMEDIATE FUTURE, get your *core* plugins from this list:
http://cordova.apache.org/docs/en/5.4.0/cordova/plugins/pluginapis.html
Get your 3rd-party plugin from this source:
http://cordova.apache.org/plugins/
When using Phonegap Build, sometimes the pluins get fixed (or updated) and this breaks Phonegap Build. This is because the "fixes" require the latest version of the compiler, and Phonegap Build is always at least one version behind.
There are two ways to deal with 3; see 4 and 5.
I have created this Worksheet. You may want to make a copy or just use it as a reference. I use this worksheet to create my demos, I so know the list is good. I am working on cli-5.2.0 right now. (Should finish by Monday or so.) However, I do not test ALL 3rd-party plugins; there are 800+ plugins.
If you fail to set the version number on a plugin, you will get the latest version. If your build fails, then set the version. If the build still fails, try the previous two or three version to find one that works. NOTE, these older plugins may have bugs that prevent you from using them. So, try an even earlier version.
Lastly, if you think you have hit a bug, then here is a page with links to the Bug respository for each plugin. Last Update is on the top left. Best of Luck.
I write a cordova application for iOS. All my files have to reside in Library/NoCloud or Documents/NoCloud (one requirement local files may not be synchronized, neither to cloud or any backup).
In cordova's config.xml I have put the following files:
<preference name="iosPersistentFileLocation" value="Compatibility" />
<preference name="iosExtraFilesystems" value="documents-nosync" />
I also tried with
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library-nosync" />
Next I request a filesystem using the following Javascript code:
window.requestFileSystem(window.PERSISTENT, 1024 * 1024 * 20, onInitFs, fileErrorHandler);
This call succeeds and I store the filesystem in a global variable. Next, I try to check if a directory exists using the following code:
window.resolveLocalFileSystemURL(directoryToCreate, resolveLocalFileSystemURLcallBackExists, onDirectoryExistsFail);
function resolveLocalFileSystemURLcallBackExists(path){
try {
fileSystem.root.getDirectory(path, { create: false }, onDirectoryExistsSuccess, onDirectoryExistsFail);
} catch (e) {
console.log(e);
}
}
Now when I debug the iOS project at some point the following Objective-C code is called:
- (NSString *)fullPathForFileSystemPath:(NSString *)fsPath
{
if ([fsPath hasPrefix:self.fsRoot]) {
return [fsPath substringFromIndex:[self.fsRoot length]];
}
return nil;
}
This function returns always nil as fs.root points to /var/.../Libriry/files and my directoryToCreate is file:///var/.../Library/NoCloud/mydir or file:///var/.../Documents/NoCloud/mydir.
Cordova version: 5.1.1
File plugin version: 3.0.0
How to write to file:///var/.../Library/NoCloud/ instead of the files subfolder?