Skip to content

Commit

Permalink
backward compability with cordova 5, it closes #129, closes #122
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Mar 1, 2016
1 parent 19c2e5e commit 861bc13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions hooks/add_swift_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ var child_process = require('child_process'),

module.exports = function(context) {
var IOS_DEPLOYMENT_TARGET = '8.0',
COMMENT_KEY = /_comment$/;
COMMENT_KEY = /_comment$/,
CORDOVA_VERSION = process.env.CORDOVA_VERSION;

run();

function run() {
var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'),
ConfigParser = context.requireCordovaModule('cordova-common').ConfigParser,
ConfigParser = CORDOVA_VERSION >= 6.0
? context.requireCordovaModule('cordova-common').ConfigParser
: context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
projectRoot = cordova_util.isCordova(),
platform_ios,
xml = cordova_util.projectConfig(projectRoot),
cfg = new ConfigParser(xml),
projectName = cfg.name(),
platform_ios = CORDOVA_VERSION < 5.0
? context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios']
: context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios'),
iosPlatformPath = path.join(projectRoot, 'platforms', 'ios'),
iosProjectFilesPath = path.join(iosPlatformPath, projectName),
xcconfigPath = path.join(iosPlatformPath, 'cordova', 'build.xcconfig'),
Expand All @@ -24,18 +30,7 @@ module.exports = function(context) {
xcodeProject,
bridgingHeaderPath;

try {
// try pre-5.0 cordova structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
projectFile = platform_ios.parseProjectFile(iosPlatformPath);
} catch (e) {
console.log("Looks like we're in Cordova 5.0 and above...");
// let's try cordova 5.0 structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
projectFile = platform_ios.parseProjectFile(iosPlatformPath);
}

// hopefully projectFile can't go null here.......
projectFile = platform_ios.parseProjectFile(iosPlatformPath);
xcodeProject = projectFile.xcode;

if (fs.existsSync(xcconfigPath)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ios/GeofencePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ func log(message: String){
}

func evaluateJs (script: String) {
if webView != nil {
if let webView = webView {
if let uiWebView = webView as? UIWebView {
uiWebView.stringByEvaluatingJavaScriptFromString(script)
} else if let wkWebView = webView as? WKWebView {
wkWebView.evaluateJavaScript(script, completionHandler: nil)
}
} else {
log("webView is null")
log("webView is nil")
}
}
}
Expand Down

0 comments on commit 861bc13

Please sign in to comment.