Skip to content

Commit

Permalink
Fix plugin to build for the Cordova 6.4.0 set
Browse files Browse the repository at this point in the history
* Bump minor version
* Call the correct pbxNativeTargetSection function from node-xcode
* Omit already installed frameworks from call to `addBuildPhase`
  • Loading branch information
Martin Bektchiev committed Mar 16, 2017
1 parent 4b18321 commit 5d0fc55
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
36 changes: 18 additions & 18 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?xml version='1.0' encoding='UTF-8'?>
<plugin
id="cordova-plugin-applewatch"
version="1.0.3"
version="1.1.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0">

<name>Apple Watch</name>

<author>Telerik</author>

<description>AppleWatch plugin for your Cordova project. You build the UI with JS, so no XCode native code hacking required.</description>

<keywords>AppleWatch</keywords>

<license>MIT</license>

<engines>
<engine name="cordova" version=">=3.8.0"/>
<engine name="cordova-ios" version=">=4.3.0"/>
<!-- When multiple SDKs are installed the check will fail, seems to be a bug in cordova-lib -->
<!--<engine name="apple-ios" version=">=8.2.0"/>-->
</engines>

<js-module name="AppleWatch" src="www/applewatch.js">
<clobbers target="applewatch"/>
</js-module>

<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="AppleWatch">
Expand All @@ -32,14 +32,14 @@
</feature>
<preference name="deployment-target" value="8.2"/>
</config-file>

<header-file src="src/ios/app/AppleWatch.h"/>
<source-file src="src/ios/app/AppleWatch.m"/>
<header-file src="src/ios/app/AppDelegate+applewatch.h"/>
<source-file src="src/ios/app/AppDelegate+applewatch.m"/>

<framework src="Foundation.framework"/>

<header-file src="src/ios/lib/headers/MMWormhole.h" />
<header-file src="src/ios/lib/headers/MMWormholeCoordinatedFileTransiting.h" />
<header-file src="src/ios/lib/headers/MMWormholeFileTransiting.h" />
Expand All @@ -49,21 +49,21 @@
<header-file src="src/ios/lib/headers/MMWormholeSession.h" />
<header-file src="src/ios/lib/headers/MMWormholeTransiting.h" />
<header-file src="src/ios/lib/headers/MMWormholeUmbrella.h" />

<source-file src="src/ios/lib/libmmwormhole-ios.a" framework="true" />
<source-file src="src/ios/lib/libmmwormhole-watchos.a" />

<!-- (1/2) THESE HOOKS ARE FOR TELERIK APPBUILDER AND ARE ENABLED IN THE appbuilder BRANCH OF THIS REPOSITORY -->
<hook type="before_plugin_install" src="src/ios/hooks/ab/prerequisites.js"/>
<hook type="before_plugin_install" src="src/ios/hooks/ab/add-targets.js"/>


<!-- (2/2) THESE HOOKS ARE FOR THE CORDOVA CLI -->
<!-- execute these once -->
<!-- <hook type="after_plugin_install" src="src/ios/hooks/cordova/copy_watchkitfiles.js" /> -->
<!-- <hook type="after_plugin_install" src="src/ios/hooks/cordova/fix_watchkitapp_buildtarget.js" /> -->
<!-- execute this one every time because the user may have done updates -->
<hook type="after_prepare" src="src/ios/hooks/cordova/copy_custom_storyboard.js" />
</platform>

</plugin>
6 changes: 4 additions & 2 deletions src/ios/app/AppDelegate+applewatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ @implementation AppDelegate (applewatch)
- (void) callJavascriptFunctionWhenAvailable:(NSString*)function {
AppleWatch *appleWatch = [self.viewController getCommandInstance:@"AppleWatch"];
if (appleWatch.initDone) {
[appleWatch.webView stringByEvaluatingJavaScriptFromString:function];
if ([appleWatch.webView isKindOfClass:[UIWebView class]]) {
[(UIWebView*)appleWatch.webView stringByEvaluatingJavaScriptFromString:function];
}
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 80 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
[self callJavascriptFunctionWhenAvailable:function];
});
}
}

@end
@end
16 changes: 8 additions & 8 deletions src/ios/hooks/ab/add-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ module.exports = function(context) {

var projectWatchKitAppPathContents = fs.readdirSync(projectWatchKitAppPath);
console.log('Adding WatchKit App files to pbxproject');
var watchAppArray = calculateFilePaths(projectWatchKitAppPath, projectWatchKitAppPathContents, new RegExp("(" + baseLproj + "|[.]h$)")); // Don't add 'Base.lproj' and all header files to compile sources
var watchAppArray = calculateFilePaths(projectWatchKitAppPath, projectWatchKitAppPathContents, new RegExp("(" + baseLproj + "|[.]h$)")); // Don't add 'Base.lproj' and all header files to compile sources

var projectWatchKitExtensionPathContents = fs.readdirSync(projectWatchKitExtensionPath);
console.log('Adding WatchKit Extension files to pbxproject');
console.log('Adding WatchKit Extension files to pbxproject');
var watchExtArray = calculateFilePaths(projectWatchKitExtensionPath, projectWatchKitExtensionPathContents, new RegExp("[.]h$")); // Don't add all header files to compile sources

// Special case Interface.storyboard
// Interface.storyboard is the only file so far
// which is inconsistent between the PBXBuildFile and PBXFileReference sections
// Interface.storyboard is the only file so far
// which is inconsistent between the PBXBuildFile and PBXFileReference sections
var storyBoardPath = path.join(projectWatchKitAppPath, baseLproj, interfaceStoryBoard),
storyBoardBuildFile = {
uuid: pbxProject.generateUuid(),
Expand All @@ -90,7 +90,7 @@ module.exports = function(context) {
name: base,
path: storyBoardPath,
sourceTree: '"<group>"',
basename: base, //this is actually a comment
basename: base, //this is actually a comment
}

pbxProject.addToPbxBuildFileSection(storyBoardBuildFile);
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports = function(context) {
},
watchKitExtensionPlistJson['CFBundleIdentifier']);

var pbxNativeTargetSection = pbxProject.pbxNativeTarget();
var pbxNativeTargetSection = pbxProject.pbxNativeTargetSection();
var mainAppTargetGuid = getUuidByComment(cordovaProjectName, pbxNativeTargetSection);
// WARNING: Workaround to correctly add libmmwormhole-watchos.a to extension target only.
pbxProject.removeFromPbxFrameworksBuildPhase({
Expand Down Expand Up @@ -276,6 +276,6 @@ function calculateFilePaths(dirname, filenames, excludingPattern) {
var filename = filenames[i];
filepaths.push(path.join(dirname, filename));
}

return filepaths;
}
}
8 changes: 4 additions & 4 deletions src/ios/hooks/ab/watchkit-common.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var fs = require('fs');

function addNativeTarget(pbxProject, prop) {
var pbxNativeTargetSection = pbxProject.pbxNativeTarget(),
var pbxNativeTargetSection = pbxProject.pbxNativeTargetSection(),
nativeTargetGuid = pbxProject.generateUuid();

console.log('Adding ' + prop.productName + ' Native Target');
pbxNativeTargetSection[nativeTargetGuid] = { isa: 'PBXNativeTarget',
buildConfigurationList: prop.buildConfiguration.uuid,
Expand All @@ -16,7 +16,7 @@ function addNativeTarget(pbxProject, prop) {
productReference: prop.productReference,
productReference_comment: prop.productReference_comment,
productType: prop.productType };

pbxNativeTargetSection[nativeTargetGuid + '_comment'] = prop.productName;
return nativeTargetGuid;
}
Expand All @@ -39,4 +39,4 @@ module.exports = {
addNativeTarget : addNativeTarget,
replacePlaceholdersInPlist : replacePlaceholdersInPlist,
quoteString: quote
}
}
6 changes: 3 additions & 3 deletions src/ios/hooks/ab/watchkit-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function addWatchkitExtensionFrameworks(pbxProject, watchKitExtension, projectPl
var coreLocationFramework = pbxProject.addFramework('System/Library/Frameworks/CoreLocation.framework');
var libmmwormholeLib = pbxProject.addFramework(path.join(projectPluginDir, 'libMMWormhole-watchos.a'));

return pbxProject.addBuildPhase([watchConnectivityFramework.path, coreLocationFramework.path, libmmwormholeLib.path],
return pbxProject.addBuildPhase([watchConnectivityFramework.path, coreLocationFramework.path, libmmwormholeLib.path].filter(i => i),
'PBXFrameworksBuildPhase', watchKitExtension + ' Frameworks');
}

Expand Down Expand Up @@ -59,7 +59,7 @@ function addWatchkitExtensionTarget(pbxProject, prop, bundleIdentifier) {

return wkcommon.addNativeTarget(pbxProject, {
buildConfiguration: watchKitExtensionXCConfigurations,
buildPhases:
buildPhases:
[{
value: prop.sourcesBuildPhase.uuid,
comment: watchKitExtension
Expand All @@ -80,4 +80,4 @@ function addWatchkitExtensionTarget(pbxProject, prop, bundleIdentifier) {
module.exports = {
addFrameworks: addWatchkitExtensionFrameworks,
addTarget: addWatchkitExtensionTarget
}
}

0 comments on commit 5d0fc55

Please sign in to comment.