diff --git a/README.md b/README.md index 4dc98fc..ed61712 100644 --- a/README.md +++ b/README.md @@ -612,6 +612,8 @@ In XCode, go to your targets and add this app group to both the phone and watch ##Tips: +Building in XCode 7 requires you to set `bitcode` to `NO` for all 3 targets. Go to 'Build Settings' and disable it 3 times. Will be fixed soon, when [MMWormhole](https://github.com/mutualmobile/MMWormhole) is updated. + For developer builds to work on a real Watch you'll need to [register the Watch UDID and add it to the provisioning profile](http://stackoverflow.com/questions/29854314/debug-on-real-apple-watch-application-verification-failed) or you'll see 'Application verification failed' when installing the app on the Watch. While you're in the iOS member center, also register an App Group (under Identifiers) and make sure you enable the App Group in the App ID you're using for your app. diff --git a/demo/index.html b/demo/index.html index 02e53a2..cfee6fb 100644 --- a/demo/index.html +++ b/demo/index.html @@ -17,11 +17,13 @@

Apache Cordova

Device is Ready

@@ -104,7 +106,7 @@

Apache Cordova

function sendTableGlance() { var payload = { - 'label2': {'value': 'Here\'s a table with a few of different colors. One even has an image!', 'color': '#FFFFFF'}, + 'label2': {'value': 'Table with a colors. ' + new Date(), 'color': '#FFFFFF'}, 'table': { // don't add selectable rows to a glance since glances are read-only 'rows': [ { @@ -113,12 +115,8 @@

Apache Cordova

'backgroundColor': '#1884C4', 'cornerRadius': 8 }, - 'label': {'value': ' images!'}, // unlike in HTML, multiple spaces have effect - 'imageLeft': { - 'data': 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', - 'width': 16, - 'height': 16 - }, + 'label': {'value': ' images!'}, // unlike HTML, multiple spaces have effect + 'imageLeft': {'src': 'www/img/logo.png', 'width': 25, 'height': 30}, 'imageRight': {'src': 'www/img/logo.png', 'width': 25, 'height': 30} }, { @@ -503,7 +501,8 @@

Apache Cordova

function initAppleWatch() { applewatch.init(function () { // register for notifications - applewatch.registerNotifications(onNotificationRegistrationSuccess, onNotificationRegistrationError); + // TODO throws 'undefined is not a function'.. setTimeout ? +// applewatch.registerNotifications(onNotificationRegistrationSuccess, onNotificationRegistrationError); }, function (err) { // an error occurred diff --git a/plugin.xml b/plugin.xml index 32e9b2f..2c95474 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ Apple Watch diff --git a/src/ios/app/AppDelegate+applewatch.m b/src/ios/app/AppDelegate+applewatch.m index bed4ccf..c0048f6 100644 --- a/src/ios/app/AppDelegate+applewatch.m +++ b/src/ios/app/AppDelegate+applewatch.m @@ -6,9 +6,22 @@ @implementation AppDelegate (applewatch) - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply { - + // requesting a bit of background processing time, useful when the app was killed instead of running in the background + __block UIBackgroundTaskIdentifier watchKitHandler; + watchKitHandler = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"backgroundTask" + expirationHandler:^{ + watchKitHandler = UIBackgroundTaskInvalid; + }]; + dispatch_after( dispatch_time( DISPATCH_TIME_NOW, (int64_t)NSEC_PER_SEC * 30 ), dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{ + [[UIApplication sharedApplication] endBackgroundTask:watchKitHandler]; + } ); + NSString* jsFunction = [userInfo objectForKey:@"action"]; + + NSLog(@"In handleWatchKitExtensionRequest, jsFunction: %@", jsFunction); + NSString* params; + // TODO 'onVoted' should not be hardcoded! if ([jsFunction isEqualToString:@"onVoted"]) { if ([[userInfo objectForKey:@"params"] isKindOfClass:[NSData class]]) { // animated gif @@ -35,7 +48,7 @@ - (void) callJavascriptFunctionWhenAvailable:(NSString*)function { if (appleWatch.initDone) { [appleWatch.webView stringByEvaluatingJavaScriptFromString:function]; } else { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 80 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ [self callJavascriptFunctionWhenAvailable:function]; }); } diff --git a/src/ios/app/AppleWatch.m b/src/ios/app/AppleWatch.m index db271a7..f708cc0 100644 --- a/src/ios/app/AppleWatch.m +++ b/src/ios/app/AppleWatch.m @@ -22,7 +22,10 @@ - (void) init:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId]; - self.initDone = YES; + // make sure the app is awake + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 500 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ + self.initDone = YES; // after a little timeout perhaps? + }); } - (void) registerNotifications:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/resources/watchkitextension/WatchKitUIHelper.m b/src/ios/resources/watchkitextension/WatchKitUIHelper.m index 8871e9a..4503103 100644 --- a/src/ios/resources/watchkitextension/WatchKitUIHelper.m +++ b/src/ios/resources/watchkitextension/WatchKitUIHelper.m @@ -72,9 +72,14 @@ + (void) setImage:(WKInterfaceImage*)image fromDic:(NSDictionary*)dic { if (namedSrc != nil) { [image setImageNamed:namedSrc]; - } - else { - [image setImageData:[dic valueForKey:@"src"]]; + } else { + // This implementation seems to use a cached version which gets lost between nav from glance to app, + // not a problem if developers use different images, but we can't expect that to be the case. +// [image setImageData:[dic valueForKey:@"src"]]; + + // so we're using this instead.. a bit less efficient but more failsafe + UIImage *img = [UIImage imageWithData:[dic valueForKey:@"src"]]; + [image setImage:img]; } [self setCommonPropertiesAndShow:image fromDic:dic];