iOS action extension Cocoapods Podfile FBSDKCoreKit 'sharedApplication' is unavailable - ios

I need the Facebook SDK in both my app and my action extension. I use Cocoapods 1.4.0, Swift 4 and Xcode 9.2. I'm having this error message coming from the FBSDKCoreKit:
'sharedApplication' is unavailable: not available on iOS (App
Extension) - Use view controller based solutions where appropriate
instead.
I've already read a lot of answers, on SOF and Github mainly. I tried a lot of suggestions. But I did not make it work.
My current Podfile:
source 'https://github.com/CocoaPods/Specs.git'
workspace 'MyApp'
use_frameworks!
platform :ios, '10.0'
inhibit_all_warnings!
def my_pods
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
end
target 'MyApp' do
my_pods
end
target 'MyAppExtension' do
my_pods
end
What I tried:
1) set Require Only App-Extension-Safe API to NO (both for my app and the extension).
2) add this to my podfile:
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == "Pods-MyAppExtension-FBSDKCoreKit"
target.build_configurations.each do |config|
//I tried both these lines
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
end

only as documentation if others arrive here:
using SPM and FB SDK 11.0 AND Xcode 12.x it works
using " " AND Xcode 13.beta for iOS13 fails:
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
PS
it's a shame using objC in 2021... :(
and ridiculous using "SWFT" Package manager containing objC, :(

Related

Including mailcore2-ios into Capacitor project: non-modular header inside framework module

I try to build a capacitor IMAP client and am therefore using mailcore2 for the iOS part of the application. However, when I install this plugin inside of my main application and then try to run it in a simulator with xcode, I get the following error:
Include of non-modular header inside framework module 'MyPlugin.Plugin_Bridging_Header'.
Code for the bridging header:
#ifndef Plugin_Bridging_Header_h
#define Plugin_Bridging_Header_h
#import "MailCore/MailCore.h"
#endif
XCode stops compiling on line 3 (#import "MailCore/MailCore.h") with the error message above.
mailcore2-ios is added as a pod inside my Podfile with a few other blocks I found through research on the web - full code below:
platform :ios, '12.0'
use_frameworks!
def capacitor_pods
pod 'Capacitor', :path => '../node_modules/#capacitor/ios'
pod 'CapacitorCordova', :path => '../node_modules/#capacitor/ios'
pod 'mailcore2-ios'
end
target 'Plugin' do
capacitor_pods
end
target 'PluginTests' do
capacitor_pods
end
post_install do |installer|
# Fix compile issues for M1 processor on mac
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
# another attempt to get rid of the non-modular header error
installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
I have no experience as an iOS developer, but as far as I understood, I need to use the bridging header to allow my app to use Swift and ObjectiveC at the same time.
I also tried the solution mentioned here, but the example here for libxml2 is not really working for mailcore (e.g. I do not have a .tbd file to add to the linked frameworks as mentioned in step 5 for iOS).
Anyone has an idea how to get mailcore working with Capacitor on iOS?

fatal error: module 'firebase_auth' not found #import firebase_auth

I am trying to use Firebase Authentication for my iOS Flutter.
I have tried all of the procedures laid out in this link but I still receive the same error.
https://github.com/FirebaseExtended/flutterfire/issues/1929
This is the error I receive when I run the iOS app.
/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module 'firebase_auth' not found
#import firebase_auth;
~~~~~~~^~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
This is my Podfile
# add pods for desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'Runner' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'Firebase/Analytics'
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
end
post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
You may be interested in this thread here: https://github.com/FirebaseExtended/flutterfire/issues/192
Essentially its recommendation is to delete Podfile and Podfile.lock. Once you've done this re-run and flutter should automatically create the correct Podfiles for you.
Hopefully that helps.
DB
When it happens remove the "^" on the dependency. So firebase_auth: ^1.0.0 -> firebase_auth: 1.0.0.

Can App Clip be used in an iOS Cocoapods project?

Our App was created in 2018 mid using Swift 4, and other 3rd party depended with Cocoapods.
I add one Clip target, the project structure is different from that given by the download link under session. Run this target, here are the crash errors:
Reason: image not found
dyld: Library not loaded: #rpath/Alamofire.framework/Alamofire
Referenced from: /private/var/containers/Bundle/Application/57185773-B735-4EE5-BB51-790DF004A85B/kt_iOS_Clip.app/kt_iOS_Clip
Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib
Here is Podfile:
platform :ios, '10.0'
inhibit_all_warnings!
target '<Main App>' do
use_frameworks!
pod 'SnapKit' , '4.2.0'
pod 'Alamofire' , '4.7.3'
......
target '<Main App>Tests' do
inherit! :search_paths
end
swift_41_pod_targets = ['Spring','PKHUD', 'FSPagerView', 'SQLite.swift','FaveButton']
post_install do | installer |
installer.pods_project.targets.each do |target|
if target.name == 'Cache'
target.build_configurations.each do |config|
level = '-Osize'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = level
puts "Set #{target.name} #{config.name} to Optimization Level #{level}"
end
end
if swift_41_pod_targets.include?(target.name)
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
end
end
target '<Main App>UITests' do
inherit! :search_paths
end
end
As other answers mentioned, separate app clip target and use_modular_headers! worked for me
platform :ios, '13.0'
target 'MainAppTarget' do
use_frameworks!
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
target 'MainAppTargetTests' do
inherit! :search_paths
end
end
target 'AppClipTarget' do
use_modular_headers!
pod 'Firebase/Analytics'
target 'AppClipTargetTests' do
inherit! :search_paths
end
target 'AppClipTargetUITests' do
end
end
I fixed this problem by adding another target in my podfile which pointed to the AppClip target
Ref: https://www.natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/
YES, but NO at present (2020.7.15).
igor-makarov had commit an app clip support to master, now just wait for next CocoaPods release.
https://github.com/CocoaPods/CocoaPods/commit/3a5deed0adfa306307027753898cca5e23be14bd
I think the right way to do it is having another target (in my case I placed it outside the main one, because I only want a few pods).
However, Cocoapods needs to update something to export/setup everything right. Since App Clips were introduced recently, Cocoapods hasn't released a new stable version with the fix (https://github.com/CocoaPods/CocoaPods/pull/9882). So we just have to wait a bit, I guess. In the meantime, you can add the Embed Pods Frameworks manually and it will work fine.
Ref: https://developer.apple.com/forums/thread/652683?login=true
What worked for me is doing:
sudo gem install cocoapods --pre
Cocoapods latest stable release at the time of this post was not supporting the app clip target with cocoaPods.

The bundle “MyProjectUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

I'm willing to add unit and UI tests to my app.
I first configured unit tests with success, I tried to do the same with UI tests. Here is my Podfile, after adding a new UI Testing Bundle target :
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!
def shared_pods
pod 'Bolts'
pod 'Branch'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
pod 'GoogleAnalytics'
pod 'GooglePlaces'
pod 'Parse'
pod 'Toast-Swift'
end
target 'MyTarget' do
shared_pods
end
target 'MyTargetUITests' do
shared_pods
end
target 'MyTargetUnitTests' do
shared_pods
end
However, when I try to run the automatically created MyProjectUITests test case, which only contains the basic setup and without even a #testable import MyProject:
import XCTest
class MyProjectUITests: XCTestCase {
override func setUp() {
continueAfterFailure = false
XCUIApplication().launch()
}
}
I'm getting this error:
Running tests...
The bundle “MyProjectUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
(dlopen_preflight(/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/MyProjectUITests): Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /private/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/Frameworks/Toast_Swift.framework/Toast_Swift
Reason: image not found)
What is wrong? Thanks for your help.
EDIT : for information, it works fine when I remove that Toast_swift pod from my UI test target and let it only in my app and unit test targets.
Check out this issue on the cocoapods github issue tracker.
I'm still a little confused as to why this became a problem but the setting the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to YES using this script fixed the issue for me.
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# This works around a unit test issue introduced in Xcode 10.
# We only apply it to the Debug configuration to avoid bloating the app size
if config.name == "Debug" && defined?(target.product_type) && target.product_type == "com.apple.product-type.framework"
config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "YES"
end
end
end
end
Try adding inherit! :search_paths
and also changing ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES in post_install
use_frameworks!
def shared_pods
pod 'SomePod'
end
target 'App_name' do
shared_pods
end
target 'App_nameTests' do
inherit! :search_paths
shared_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
end
end
end
I too faced this issue and none of the other suggestions worked.
After a while I found out that specifically using print() anywhere in your code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.
I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.
Hope this helps!

How to specify specific source for a certain pod?

Although I believe this is harmless, warnings quite irk me. So I'm using a very specific version of TwilioChatClient together with TwilioClient. These two specific versions are what Twilio have been using in their sample projects.
Anyways, the warning when installing / updating pods:
[!] Found multiple specifications for TwilioChatClient (1.0.9):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.9/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.9/TwilioChatClient.podspec
[!] Found multiple specifications for TwilioChatClient (1.0.8):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.8/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.8/TwilioChatClient.podspec
[!] Found multiple specifications for TwilioChatClient (1.0.7):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.7/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.7/TwilioChatClient.podspec
[!] Found multiple specifications for TwilioChatClient (1.0.6):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.6/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.6/TwilioChatClient.podspec
[!] Found multiple specifications for TwilioChatClient (1.0.5):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.5/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.5/TwilioChatClient.podspec
[!] Found multiple specifications for TwilioChatClient (1.0.4):
- /Users/XXX/.cocoapods/repos/master/Specs/7/d/e/TwilioChatClient/1.0.4/TwilioChatClient.podspec.json
- /Users/XXX/.cocoapods/repos/twilio/TwilioChatClient/1.0.4/TwilioChatClient.podspec
My podfile:
project 'Proj/Proj.xcodeproj'
source 'https://github.com/CocoaPods/Specs'
source 'https://github.com/twilio/cocoapod-specs'
platform :ios, '10.0'
use_frameworks!
target 'Proj' do
pod 'TwilioClient', '~>1.2' # Twilio Call Framework
pod 'TwilioChatClient', '1.0.4' # Twilio Chat Framework
target 'MobileMedTests' do
inherit! :search_paths
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
end
target 'ProjUITests' do
end
I think specifying two kinds of sources (which are both necessary) causes these warnings. Is there a way to put the specific source right beside the pod?
In fact, your problem comes from the fact that you have added the twilio repo to your pod source with this line :
source 'https://github.com/twilio/cocoapod-specs'
So when you type pod repo, you obtain something like :
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/cyrille/.cocoapods/repos/master
twilio
- Type: git (master)
- URL: https://github.com/twilio/cocoapod-specs
- Path: /Users/cyrille/.cocoapods/repos/twilio
And when you execute pod install, cocoa pods can find a version of this lib both in master's cocoapods repo and in twilio's one... which make the warning.
To remove this warning, remove this line from your Podfile :
source 'https://github.com/twilio/cocoapod-specs'
In a terminal execute the following commands :
pod repo remove twilio
and then :
pod update
You should get the following with no more warnings :
Analyzing dependencies
Removing TwilioClient
Downloading dependencies
Installing TwilioChatClient 2.2.0 (was 1.0.4)
Installing TwilioSDK (1.2.9)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
just wanted to give a bit of background on the warnings you saw here. We use a separate cocoapods repository during beta testing (https://github.com/twilio/cocoapod-specs) but began publishing to the global cocoapods repository soon after GA when 1.x was released.
We did not stop publishing to our existing cocoapod-specs repository for the rest of the 1.x releases because it would have been a breaking change to existing customers using the beta source line who wished to upgrade if they did not also have the global cocoapods repository declared. This is what cocoapods is warning about, that the same pod with a same version is defined in two places. The podspecs are identical, so this will not cause issues when using any of the versions of the SDK for which this warning shows up.
As of 2.x, we have been publishing chat only to the global repository so that is why the warnings stop with the 1.x series of releases.
First, You need SDK also.I installed pod on my project now. It works fine. Look up this link
http://cocoapods.org/?q=Twilio
Pod Code
project 'Proj/Proj.xcodeproj'
source 'https://github.com/CocoaPods/Specs'
source 'https://github.com/twilio/cocoapod-specs'
platform :ios, '10.0'
use_frameworks!
target 'Proj' do
pod 'TwilioSDK', '1.2.9'
pod 'TwilioChatClient'
target 'MobileMedTests' do
inherit! :search_paths
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
end
target 'ProjUITests' do
end
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '10.0' # (or whatever version you want)
target 'Project Name' do
pod 'TwilioSDK', '1.2.9'
pod 'TwilioChatClient'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
end
end
end

Resources