Cocoapods: Embedding a framework in an iMessage App

Created on 14 Sep 2016  路  46Comments  路  Source: CocoaPods/CocoaPods

What did you do?

Created an iMessage app, not a normal iOS app, added a Podfile and ran pod install. After some development, archived and uploaded the app.

What did you expect to happen?

Everything to go smoothly; which it did until I tried to upload the app to the App Store. CocoaPods works nicely with iOS apps containing iMessage extensions, but iMessage apps need to be handled differently as stated here: https://developer.apple.com/library/content/qa/qa1936/_index.html

What happened instead?

App Store upload failed while verifying assets. To get a clear error message I gave it a retry with Application Loader, and:

screenshot 2016-09-13 21 09 23

CocoaPods Environment

Stack

   CocoaPods : 1.1.0.rc.1
        Ruby : ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
    RubyGems : 2.0.14.1
        Host : Mac OS X 10.11.6 (15G1004)
       Xcode : 8.0 (8A218a)
         Git : git version 2.9.3
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 09ab902b44a321cfe9352b0c9c4d63f02da552d9

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.1
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.0.0
cocoapods-try         : 1.1.0

Podfile

platform :ios, '10.0'
use_frameworks!

target 'AppName' do
end

target 'MessagesExtension' do
  pod 'SwiftyJSON', :git => 'https://github.com/acegreen/SwiftyJSON.git', :branch => 'swift3'
  pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
  pod 'UIScrollView-InfiniteScroll'
  pod 'Shimmer'
  pod 'ReachabilitySwift', :git=> 'https://github.com/ashleymills/Reachability.swift.git', :branch => 'feature/ios10'
  pod 'SDWebImage'
  pod 'TransitionManager', :git => 'https://github.com/cemolcay/TransitionManager.git', :branch => 'swift3'
  pod 'SwiftyStoreKit', :git => 'https://github.com/isair/SwiftyStoreKit.git', :branch => 'swift-3.0'
  pod 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess', :branch => 'swift-3.0'
  pod 'Fabric'
  pod 'Crashlytics'
  pod 'Toasty', :git => 'https://github.com/isair/Toasty.git', :branch => 'swift3'
  pod 'AWSCore'
  pod 'AWSKinesis'
end

Project that demonstrates the issue

Project is commercial. However this can easily be tested by creating a new project, selecting iMessage App, then adding a framework to it via CocoaPods.

awaiting input

Most helpful comment

@andrewwilliams if you have a Gemfile, you can put this line in it to try out this branch of CocoaPods:

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :branch => 'basher_messages_app_build_phase'

You can find out more info at bundler.io

All 46 comments

Interesting. This was done intentionally because messsages apps don't have a user-modifiable Target Dependencies build phase. I can put up a PR soon that fixes this.

@isair can you try a Gemfile that looks like this:

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :ref => 'adaf73e925178061bf3d05bcaecf3288982597d9'

This branch removes the special check for messages applications. If you can submit successfully with this, then I'll start the PR, which should move pretty quickly.

Updated the sha, since I've rebased

Successfully archived and uploaded the app. However, when downloaded through TestFlight, the app simply freezes on every launch. Tested on two different devices. Debug builds work fine as before.

@isair great! For the not launching in release configuration, make sure your NSExtensionPrincipleClass key in your extension's info plist uses $(PRODUCT_MODULE_NAME). to prefix your class. So if your view controller for your messages app is MessagesViewController, then the value should be $(PRODUCT_MODULE_NAME).MessagesViewController. We ran into this issue as well, and that fixed it for us.

@isair I'm going to start the PR, but I'd appreciate if you tried that and got back to me. If that doesn't fix it, you'll need to look at your device logs on launch to see where it's failing. If it launches okay in debug, then the search paths for frameworks are probably okay, which would mean CocoaPods is doing what it's supposed to.

@benasher44 My extension uses NSExtensionMainStoryboard instead. I'll check the device logs. I believe treating message extensions in message apps as normal might be causing this issue, though. Apple tells developers to embed frameworks in an aggregate target instead of the app target itself for message apps.

Edit: The freezing issue doesn't happen when pod sources are simply carried inside the project.

The only targets in play in this scenario are the messages app and the extension. So, it has to be in one or the other. Let me know what the logs tell you though. You will might need some kind of prefix for your storyboard name, but I'm unsure

With the prefix, it's just unable to find the storyboard file. I've checked the logs but interestingly when the freeze happens nothing gets logged for the MessagesExtension or any other process.

Can't CocoaPods create an aggregate target in the workspace and add that as a target dependency for the extension?

Even it did, that target would have to be included with your application, which wouldn't be different than the existing targets you have. Can you try getting your messages application to launch without any pods in a production setting? This would be a good start to working toward the problem. Sorry for the long build test cycle here. Looks like you're the first (that I know of) to submit a messages application with cocoapods.

Actually sorry I reread your question, and I understand what you're asking better. Originally it was creating an aggregate target and putting it in your extension. That's what was in the frameworks directory that got your app rejected.

Also I might as well check, can you tell me what the runpath search paths are for your extension?

Hi, I've the same problem with my iMessage App. I tried with your Cocoapods's version, archived and uploaded worked great, but few moment after I receive a mail from Apple that say : "Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path." Have you more informations about this message ?

Sorry for the late reply.

It works in a production setting without CocoaPods integration. Since I had to do a release the day I opened this issue, I simply carried the source code for the pods I used inside the project and solved a couple namespace issues to make things work.

The runpath search paths for my extension are: $(inherited), @executable_path/Frameworks, and @executable_path/../../Frameworks.

@isair I'm at a bit of a loss here. The best I can do without logs is go through with the PR to treat messages extensions just like other extensions, since that at least allows you to submit and seems like the best step forward at this point.

I've double checked all of the places I can think of. Extensions are meant to load frameworks from within their host app, and that works fine in every other case (including messages extensions within iOS applications, one of which I've successfully submitted).

In general, when you plug in your device and look at the logs from your device via the Xcode Devices window, I would expect their to be lots of logs, regardless of whether or not you've loaded an app. Therefore, I'm a bit surprised to hear there were none. If you can get any logs within +/- 2 minutes of launching your TestFlight app, you're welcome to DM them to me on Twitter or anywhere else if you're not comfortable sharing them here. At least that way, we can have another pair of eyes on them. It's near impossible to debug this without logs.

@pierrolivier if you can get a TestFlight submission downloaded, I'd appreciate any info you could get from logs as well.

The first PR was merged, since it at least unblocks App submission. I'd still like to see if there's more CocoaPods can do here to help with getting this working. To do that though, I'll need more info to figure out the root cause.

I've started a new iMessage app project. I've set a gemfile with cocoapods master version and I've added 3 pods to my Podfile ( Alamofire, Kingfisher, SwiftDate ). My app crashed at startup

dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire Referenced from: /Users/pierro/Library/Developer/CoreSimulator/Devices/21617CED-0C1F-4FF7-A8F9-73117A596E54/data/Containers/Bundle/Application/9ED3E3E4-A661-4675-B3F3-912D6A56323A/Scoores.app/PlugIns/MessagesExtension.appex/MessagesExtension Reason: image not found (lldb)

Thanks.

Hey everyone! I've put up a PR (linked directly above this comment) that should fix the remaining iMessage app issues. If you all could try it out and give feedback, that'd be much appreciated!

It's works ! Thanks

I'd love to try this out as I'm having the same issue but I'm not sure how to test out the fix that you've posted above (sorry!). If anyone has time, can you point me in the right direction?

Thanks!

@andrewwilliams if you have a Gemfile, you can put this line in it to try out this branch of CocoaPods:

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :branch => 'basher_messages_app_build_phase'

You can find out more info at bundler.io

Hallelujah, it worked! Thanks so much for your help @benasher44.

The PR to fix this has been merged

@benasher44 I see you've closed this but I'm still having this issue.

Using OS X 10.11.6, XCode 8.0 and Cocoapods 1.1.0.rc.2 - any guidance is much appreciated.

Hey! It's fixed on master, it'll be available in an upcoming release.

Thanks for answering -- pardon my ignorance I'm not super familiar w/ Github.. is there a way to install the master now (through the command line) or is there a way to do it from Github?

No worries! Checkout bundler.io for more info on how to setup a Gemfile and add a gem that points at a git branch.

@isair Did you get Answers Analytics working for your iMessage Extension?

@otymartin Answers sadly doesn't support app extensions yet.

@isair so very sad indeed :(

If we're trying out master branch Cocoapods, do we just need to redo pod install to get this fix applied? Or is there another step?

pod install should be enough

I created a Gemfile in my project directory thats contains the following:

source 'https://rubygems.org'

gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git'
gem 'xcodeproj', :git => 'https://github.com/CocoaPods/Xcodeproj.git'

gem 'cocoapods-keys', :git => 'https://github.com/orta/cocoapods-keys.git'

and ran bundle install. Then I ran a pod install. Re-Archived and re-uploaded via Application Loader but I'm still seeing the same issues in the original post. Anything I missed?

It failed to upload? What was the error message? Can you post your podfile and a sample project if possible?

Can you confirm the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES setting for your extension? The one in the sample seems okay.

screen shot 2016-10-09 at 2 33 46 pm

I have it as $(inherited)

Ah as odd as it may seem, you should highlight that setting and hit backspace to delete it, and then that should set it to No. If that doesn't do it, just set it to No.

When it's set to Yes, Xcode embeds the Swift (Foundation, etc.) frameworks into the extension, which is what the App Store is complaining about.

Ah, that makes sense. I hit backspace, and it defaulted to Yes. So i set it to No. It still didn't solve the issue (tried it with both my real extension and the sample project)
I set it to No for just the Messages extension.

It might be set at the project level then. In any case, you just have to figure out how you like your build settings :). But, I think we've got this one figured out.

I don't have build settings that I prefer. I've done no fiddling with the build settings/phases other than the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES option we just changed, which I changed originally because of a warning from pod install.

screen shot 2016-10-09 at 6 15 22 pm

Im sorry for my ignorance but I do not have this figured out. Setting it at project level did not work for me.. I made sure to clean before re-archive.

Hmm okay. Can you tell me the current state of those build settings? How's it set at the project and target levels?

Turns out I forgot to do bundle exec pod install instead of pod install after grabbing latest version via Gemfile. Super sorry about the trouble! 馃榿

No prob! All working now?

Yup!

Hello,
I just met the same issue as @isair with cocoapods version 1.1.0.
My application and iMessage extension were building fine, then the upload to Testflight was fine too. However, when I open my iMessage application from release IPA, the application freeze at launch without log. I think it's because my iMessage extension can't find frameworks from cocoapods.
I solved my problem running 'pod install' with cocoapods 1.2.0.beta.3. Then release version from Testflight works great.

@youboox I'm glad you got it worked out, and we appreciate you posting the resolution. Have a great day!

Was this page helpful?
0 / 5 - 0 ratings