alunny / node-xcode

tools and utilities for working with xcode/ios projects
Apache License 2.0
225 stars 105 forks source link

Apple Watch app integration #77

Open sebastien-p opened 8 years ago

sebastien-p commented 8 years ago

Hi,

I use to write Cordova applications which, I figured, make use of node-xcode under the hood to help automating stuff.

Now the problem is I'm not used to XCode and I need to automate the integration of an Apple Watch application. I plan on packaging the watch application as a Cordova plugin and use the provided hooks feature to get around some limitations of such plugins by editing some parts of the XCode configuration myself.

So I wrote some NodeJS code based on node-xcode. Parsing and writing to .pbxproj files was easy but - to me - adding stuff to them is not, node-xcode not being documented sadly isn't helping.

I found some occurrences of watch related code (pbxProject.js#L1418-L1419, pbxProject.js#L1541-L1542, pbxProject.js#L1559-L1560) so I guess what I want to achieve should be possible, maybe even fairly easily. But I'm stuck as I don't know what I need to add to the project file so that XCode would be aware my Cordova app contains an Apple Watch app. The only thing I believe I did right was to add new target like this config.addTarget('watch app', 'watch_app'); and clearly this is far from enough.

So, to all the Obiwan Kenobis out there: you are my only hope. Could you guys point me to the right direction please? Do you know of any resources I can read to help me understand the XCode project file better in this case (besides this one)? Do you know someone that already automated the integration of an Apple Watch app in a Cordova app? Anything you can share I'd take at this point.

Many thanks!

revolunet commented 8 years ago

cordova-lib makes extensive use of node-xcode so maybe you can find examples there ? https://github.com/apache/cordova-lib/blob/ba30bfda5860f672f5e2901e9d15c7daab566b71/cordova-lib/src/cordova/metadata/ios_parser.js

sebastien-p commented 8 years ago

I did that, that's even how I found out about this node module. The thing is the lack of documentation here isn't the main problem, my lack of XCode knowledge is :smile:. And a Google search doesn't really bring anything up on the Cordova+Apple Watch app automation topic. I can't believe I'm the only one who need to do such a thing.

imhotep commented 8 years ago

Sometimes, code is documentation and that is hopefully the case with this node-xcode project. The method signatures in pbxProject.js are pretty self-explanatory. As far as your specific case, there seems to be some sort of support for Apple Watch as a target but if you need to know exactly how to configure your project with this library this is how I would do it: 1) start with a fresh cordova project (save a backup of the pbxproj file) 2) add all the watch related stuff (code, frameworks, targets etc...) 3) diff the two pbxproj files and see which sections are being updated.

Step 3) is the hardest. You might find some helper methods in pbxProject.js that add references to the right sections or you might have to write your own (pull requests welcome!). If you need assistance with this process, we can talk some more.

May the source be with you!

revolunet commented 8 years ago

Thanks @imhotep !

sebastien-p commented 8 years ago

@imhotep Thanks. Agreed sometimes code is documentation and method signatures here are self-explanatory but still I think some things should be documented. For example, one can add a resource file to a given target (pbxProject.js#L231), trying to do that I passed the name of my target and it didn't work, then I figured that the addTarget returns a target object (pbxProject.js#L1343) so I tried to pass a reference to that object which didn't work either. Third try: I passed target.uuid, success. See, it didn't take me that much time to make it work but I'm pretty sure I won't be the only one not to have it right on first attempt.

Now, your 3-steps process is exactly what I did before crying for help :smile:. Diffing the two .pbxproj files show more than 40 differencies, mostly stuff that I don't understand due to my lack of XCode knowledge. I mean, what are PBXContainerItemProxy and PBXVariantGroup anyway? Also, adding a 'watch_app' type target using node-xcode produces lines like BEC0505C1C6E39FF00E85095 /* watch app.undefined */ whereas clicking buttons in XCode adds a .app extension instead of .undefined, does it really matter? Do PBXGroups matter too in my case (or are they just virtual XCode UI folders)? I find it really hard to guess how stuff like that work and how targets/sources/resources/groups... should be linked without any kind of documentation (maybe there's an official .pbxproj documentation somewhere you guys could point me to?).

So yeah, step 3) is the hardest, it feels like Samsung reverse engineering I won't be able to make it work alone as quickly as I should. Good news is the OSS community is awesome, thank you for node-xcode and thank you for helping me out :+1:!

sebastien-p commented 8 years ago

A bunch of resources I could find:

Well, that's a start.

imhotep commented 8 years ago

@sebastien-p Hit me up on Cordova Slack or #cordova on irc.freenode.net and we can chat some more about this.

patniemeyer commented 8 years ago

@sebastien-p Were you ever successful with this? I would like to do the same and I'm wondering if this approach is too fragile right now for app extensions. Thanks.

sebastien-p commented 8 years ago

@patniemeyer The Apple Watch integration has been put on hold while we refactor our whole application. I sadly have no news from @imhotep on the topic but hopefully I could talk to him next week at PGDEU.