Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18337] iOS: Allow manual addition of WatchKit/Share Extension to Titanium application

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-02-28T15:33:57.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0, Release 4.1.0
ComponentsiOS
Labelsn/a
ReporterIngo Muschenetz
AssigneeJon Alter
Created2015-01-07T17:27:36.000+0000
Updated2017-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

FileDateSize
ScreenshotFiles.png2015-04-16T16:36:16.000+00008458
ShareExtention.zip2015-02-24T23:44:11.000+0000211497
WatchKitSupport.zip2015-04-16T00:09:32.000+00004827

Comments

  1. Mads Moller 2015-02-16

    Could be cool to add keyboards to an app, like this: https://github.com/ryanfb/iOS-Ancient-Greek-Keyboard
  2. Jon Alter 2015-02-18

    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_.

       <modules/>
       <extensions>
           <extension projectPath="/Users/jalter/Projects/TodayExtension/Test1">TestToday</extension>
       </extensions>
       

    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.html

    App 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
       <key>com.apple.security.application-groups</key>
       <array>
           <string>group.jalter.TodayExtentionSharing</string>
       </array>
       
  3. Jon Alter 2015-02-18

    [~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_.

  4. Jon Alter 2015-02-24

    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.
  5. Rick Blalock 2015-03-01

    [~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
  6. Rick Blalock 2015-03-01

    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).
  7. Jon Alter 2015-03-02

    We are not able to launch the WatchKit app in the sim yet.
  8. Jon Alter 2015-03-09

    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
  9. Hans Knöchel 2015-03-10

    Thank you Jon, great work! One question: If not in the simulator, how are we able to test the watchkit apps, yet?
  10. Malcolm Hollingsworth 2015-03-10

    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.
  11. Jon Alter 2015-03-10

    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 using simctl.

        xcrun simctl launch booted <app identifier of the watchkit app>
        
  12. Joseph Sachs 2015-03-10

    I'm assuming we can't create *currently* in XCode the Today's Extension for a Ti App in Swift? Or is it possible?
  13. Jon Alter 2015-03-10

    [~underlabs] Swift extensions are working fine on my end. Try it out and let us know how it goes.
  14. Mads Moller 2015-04-09

    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 tag in tiapp.xml. Followed Jon Alters guide. 3. Im using the Ti SDK 4.0.0.Beta2 4. Currently I cannot get titanium to open the watchkit simulator - so I just assume that it works. I can tell from the build log that titanium is picking up the extension and adding it. 5. Ive created 3 app ids, and 3 provisioning profiles. 1 for the app, 1 for the watchkitapp and 1 for the watchkit extension 6. ive gone into xcode and code signed the different apps with their appropiate provisioning profile. 7. back into Ti Studio and Package the app for iOS Itunes Store (like i normally would). This works fine. 8. the app is added to the xcode archieves, and I try to validate the app against apple rules. 9. Booom! Validation errors. see image: http://cl.ly/image/0v150w212V2O What can I do to get this shipped to approval? Mads
  15. Jamie Druce 2015-04-15

    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: Unable to start plugin [MY_WATCH_APP_EXTENSION_BUNDLE_ID] 0x7fd142f2bac0 with identifier [MY_WATCH_APP_BUNDLE_ID] (Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)" (connection to service named [MY_WATCH_APP_EXTENSION_BUNDLE_ID] UserInfo=0x7fd142e48700 {NSDebugDescription=connection to service named [MY_WATCH_APP_EXTENSION_BUNDLE_ID] }) 2015-04-15T09:50:11.880 companionappd[12756] (Error) WatchKit: activePlugInForIdentifier: returned nil for application [MY_WATCH_APP_BUNDLE_ID] It seems like the app cannot communicate with the phone extension, is this a bug in Titanium's compiling of the project? Any help with this is would be greatly apprechieated as it is almost Watch launch day and nothing is working! Jamie.
  16. Mads Moller 2015-04-15

    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.
  17. Jon Alter 2015-04-16

    [~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 attached WatchKitSupport.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.
  18. Mads Moller 2015-04-16

    Hallelujah !! That actually works. Ive sent my app to review now.. fingers crossed.
  19. Jamie Druce 2015-04-16

    Well whatever it is, it has certainly done the trick! It is now in review. These are nervous times..
  20. Jamie Druce 2015-04-20

    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!
  21. Lee Morris 2017-03-31

    Closing ticket as fixed, if there are any problems, please file a new ticket.

JSON Source