[TIMOB-18337] iOS: Allow manual addition of WatchKit/Share Extension to Titanium application
GitHub Issue | n/a |
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-02-28T15:33:57.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 4.0.0, Release 4.1.0 |
Components | iOS |
Labels | n/a |
Reporter | Ingo Muschenetz |
Assignee | Jon Alter |
Created | 2015-01-07T17:27:36.000+0000 |
Updated | 2017-03-31T22:22:19.000+0000 |
Description
We need to investigate building a native share extension (and/or WatchKit app) and package that with a Titanium application.
This should result in the ability for an end user to drop this compiled piece into a Titanium project, and the CLI will understand how to package it correctly as part of the generated application
Attachments
Could be cool to add keyboards to an app, like this: https://github.com/ryanfb/iOS-Ancient-Greek-Keyboard
PR (Work in progress): https://github.com/appcelerator/titanium_mobile/pull/6647 This PR will allow extension _targets_ in external Xcode projects to be defined in the _tiapp.xml_. These extensions will be built and signed with the same certificate as the app (this is important) and then included in the titanium app. Please see the notes below for more details.
Notes:
Extensions currently need to be build natively.
Xcode 6.2 (beta) or newer must be installed to work with watchkit extensions
Currently WatchKit apps are will not launch in the simulator
The *projectPath* (defined in the _tiapp.xml_) must be absolute. Relative paths and using "~" are NOW supported on master.
The *Product Name* of the app extension must be *$(TARGET_NAME)*.
The *Bundle Identifier* of the app extension must begin with the *Bundle Identifier* of the app it will be included in. For example, if the bundle id of the app is _com.jalter.test_ then the bundle id of the extension could be _com.jalter.test.greekkeyboard_.
The app and the extension(s) should have different provisioning profiles unless using a *
If changes are made to the extension and they don't exist when the Titanium app is build, clean the build directory.
Testing
Create an extension in Xcode
In the *tiapp.xml* of your titanium app, add an *extensions* tag (next to the modules tag).
In the *extensions* tag, add an *extension* tag.
Add an attribute named *projectPath* to the *extension* tag. The value of the attribute should be the absolute path to the folder containing the Xcode project with your extension.
The _content_ of the *extension* tag should be the *target* name of the the extension in the Xcode project
Build your titanium application like normal for _simulator_ or _device_.
New APIs added to support extensions
To use these new features, an *App Group* must be setup for the app and the extension. See the *App Group* section for notes. See the docs for API usage examples.*Ti.App.iOS.UserDefaults* is a new proxy that is essentially the same as Ti.App.Properties except it can be used to write to properties that are shared within an *App Group*.
*Ti.Filesystem.directoryForSuite* is a new method that returns the the path to a directory shared within an *App Group*.
*Ti.Database.open/install* methods now accept either a database name or a full path. This allows for the database to live in the directory returned by _directoryForSuite_.
#* Developers of native extensions need to be careful not to create deadlocks when writing to shared directories https://developer.apple.com/library/ios/technotes/tn2408/_index.htmlApp Group Setup
Add the “App Groups” entitlement to your App ID (in the Provisioning Portal)
Add the “App Groups containers” entitlement to your App ID (in the Provisioning Portal)
Add the “App Groups” entitlement to your entitlements file
#* Use a custom Entitlements.plist by copying it from the build dir into the root of the app project next to Resources. Edit the file to add your app group[~viezel] If you would like to try this PR with the extension you mentioned. Make sure you pay special attention to the following points as they will both need to be changed in the Xcode project in that repo:
The *Product Name* of the app extension must be *$(TARGET_NAME)* (change this under *Build Settings*)
The *Bundle Identifier* of the app extension must begin with the *Bundle Identifier* of the app it will be included in. For example, if the bundle id of the app is _com.jalter.test_ then the bundle id of the extension could be _com.jalter.test.greekkeyboard_.
More Testing Resources
* *ShareExtention.zip* (attached to this ticket) Xcode project with native extensions that can be used for testing. Can be used with the titanium example app to test some of the new features. * *[Titanium Example gist](https://gist.github.com/jonalter/bdd224974368899b78a8)* Shows writing to UserDefaults and Filesystem * Download the latest ci build from the [master branch](http://builds.appcelerator.com.s3.amazonaws.com/index.html#master) The *Bundle Ids* and *App Group id* for of these examples will need to be changed.[~jalter] - Trying to play with this today as I have some time. Here are some things I ran in to: 1. I must be doing something wrong because when I point to the extension, I get: https://db.tt/wmQpFlTv 2. if I point to the root dir that has the Xcode project (not the extension dir), I get: https://db.tt/3ZG0nYSv 3. Here's my complete setup, per your instructions above: - Product Name: https://db.tt/edXUzQmD - tiapp.xml - https://gist.github.com/rblalock/f1354acd9e34356795fb - Bundle ID: com.xidlabs.WatchKitExample.Sample.watchkitextension - Ti APP ID: com.xidlabs.WatchKitExample
Ok #2 was my bad. I needed to make sure xcode-select was pointed at the right Xcode. The app compiles and runs now. The watch kit app doesn't run though. This might just be my ignorance in how its supposed to boot up but right now the watch sim just has a black screen (unlike the app extension...which has a label and a button I dropped on there).
We are not able to launch the WatchKit app in the sim yet.
Backport to 3_5_X: https://github.com/appcelerator/titanium_mobile/pull/6700 Reverting backport to 3_5_X: https://github.com/appcelerator/titanium_mobile/pull/6750 Backport to 4_0_X: https://github.com/appcelerator/titanium_mobile/pull/6751
Thank you Jon, great work! One question: If not in the simulator, how are we able to test the watchkit apps, yet?
I might be guessing here, but I read it as you did first time - but re-reading I noticed the word in the middle. "We are not able to *launch* the WatchKit app in the sim yet." Guessing that means you manually launch it and then run the project - phone sim starts, watch sim would be ready. If it means you also/instead of manually start the app from the sim launcher the compile and press the icon when the console says finished. Again - not tried yet, just a guess. I now do not take it to mean you _cannot_ simulate.
The Titanium CLI isn't yet able to *launch* the WatchKit app in the simulator although it is packaged and installed. Here are a couple options that should get you going until this functionality is available through Titanium.
Launch the WatchKit app from the Xcode project that was used to build it. This will not test it running with a Titanium app, but it is probably the fastest way to get it running in the sim. Xcode supports launching WatchKit apps in the sim to any of the app's interfaces (*Main*, *Glance*, *Notification*).
Build and run the Titanium app that contains the WatchKit app. Once the Titanium app (with a WatchKit app) is launched in the simulator, you can launch the simulator app using
simctl
and the bundle id of the WatchKit app. This will allow you to launch the *Main* interface. I am not currently aware of a way to launch to the *Glance* or *Notification* interfaces usingsimctl
.I'm assuming we can't create *currently* in XCode the Today's Extension for a Ti App in Swift? Or is it possible?
[~underlabs] Swift extensions are working fine on my end. Try it out and let us know how it goes.
Hi all, Im about to send my app to apple approval, but I cannot get xCode to successfully validate my watchkit app. This is what I did: 1. Ive created a native watchkit app and extension and it works great in xcode. 2. ive linked the extension and titanium together using the new
I have built a native WatchKit exstension that runs perfectly in the simulator. After linking it to my Titanium project, it builds succesfully without error. Using the "xcrun simctl launch booted [MY_WATCH_APP_BUNDLE_ID]" comand, the watch app gets launched, but all i see is the spinning 'loading' wheel. Upon investigation of the logs, i found the following errors: 2015-04-15T09:50:11.879 companionappd[12756] (Warn ) WatchKit:
It seems like this phase 1 had the scope of compiling a version of a titanium app where the extension is bundled for testing. This seems to work. What does not seem to work is how would be want to distribute it to App Store. Using the Titanium CLI it will create a xcode project with an embedded watchkit extension. This is great, but since the generated xcode project have only 3 targets (projectname, projectname-iPad and projectname-universal) and not the two new target of "projectname WatchKit Extension" and "projectname WatchKit App", then how would that ever work? It seems that xcode needs those two new targets in order to create a xcarchive for App Store that actually contains the watchkitextension (WK). if im wrong - then at least have the generated xcode project point to the embedded extension targets.
[~jdrucey][~viezel] I haven't yet been able to reproduce the [~jdrucey]'s issue regarding launching the watch app bundle id via simctl yet. I was able to reproduce the issue where Apple emails you with a message about an "Invalid Binary" after you up "Submit to App Store...". Follow the instructions below and let me know how it goes. 1. Build your Titanium app for the App Store 2. In the xcode organizer right/ctrl click on the "Archive" and click "Show in Finder" 3. In the finder right/ctrl click on the
.xcarchive
file and click "Show Package Contents" 4. Unzip the attachedWatchKitSupport.zip
and add it to your.xcarchive
as seen here: !ScreenshotFiles.png! 5. Submit the archive to the App Store and let us know your results. Thanks for your help.Hallelujah !! That actually works. Ive sent my app to review now.. fingers crossed.
Well whatever it is, it has certainly done the trick! It is now in review. These are nervous times..
So, not all is as it seems, app was rejected by Apple as the Watch app simply does not work. This is still an issue!
Closing ticket as fixed, if there are any problems, please file a new ticket.