Using Firebase in the App and Today Extension doesn't work - ios

I'm using Firebase in My App, I used it via pod and everything was work correctly,
Then we Add Today Extensions (2 extensions) to our app, and also we need to use Firebase in it, so I added it to podfile like this:
use_frameworks!
project ‘projectName.xcodeproj'
target ‘appName’ do
pod 'Firebase/Core'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
end
target ‘todayExtension1_Name’ do
pod 'Firebase/Core'
end
target ‘todayExtension2_Name’ do
pod 'Firebase/Core'
end
and I create two apps for the todayExtensions, and implement the .plist files correctly and the app build successfully.
but when I try to run the app, I got this runtime exception:
dyld: Symbol not found: _OBJC_CLASS_$_GTMLogLevelFilter
Referenced from: /Users/rawanal-omari/Library/Developer/CoreSimulator/Devices/33A7DC45-EFD9-4245-8989-7C6B4194481F/data/Containers/Bundle/Application/84C060C2-A4AE-4AF3-8804-ADA8CFBCABB3/appName.app/appName
Expected in: /Users/rawanal-omari/Library/Developer/CoreSimulator/Devices/33A7DC45-EFD9-4245-8989-7C6B4194481F/data/Containers/Bundle/Application/84C060C2-A4AE-4AF3-8804-ADA8CFBCABB3/appName.app/Frameworks/GoogleToolboxForMac.framework/GoogleToolboxForMac
in /Users/rawanal-omari/Library/Developer/CoreSimulator/Devices/33A7DC45-EFD9-4245-8989-7C6B4194481F/data/Containers/Bundle/Application/84C060C2-A4AE-4AF3-8804-ADA8CFBCABB3/appName.app/appName
Did anyone face problem like this?

Not sure if targeting the extensions via pods is enough,
But the following steps are needed
Step 1. Go to your firebase console.
Step 2. Click on the project you are working on.
Step 3. Within the project, click on "Add another app"
Step 4. Select iOS and then enter the BUNDLE ID of your TODAY EXTENSION
Step 5. Complete the wizard and download the generated GoogleService-Info.plist file. Add the plist file to your Today Extension's root folder
From here you can try adding firebase via pods to your extensions.

I had the same problem. In my case I've added the 'Firebase/Performance' pod to the app target, but not to the extension target. After adding it to the extension too, I was able to run the app again.
Conclusion: add the Firebase pods you're using in your app target, to the extension target too

Related

Why am I getting "No such module 'ESPProvision'" Error in swift even though the pod is installed?

I am attempting to run sample code from Esprissif for their ESPProvision library, it comes with the following podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
target 'ESPProvisionSample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for ESPProvisionSample
pod 'ESPProvision'
pod 'MBProgressHUD'
target 'ESPProvisionSampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'ESPProvisionSampleUITests' do
# Pods for testing
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'YES'
config.build_settings['ARCHS'] = 'arm64'
end
end
end
This runs successfully when I run pod install and the pods seem to be correctly installed within the pod file structure, however when i try to build the project I get the error:
No such module 'ESPProvision'
I am new to coding in swift, but in my previous project, simply having the pod file installed was enough for the file to be able to be found anywhere within the code of the app. Do I need to explicitly call the library using its relative pwd?
I also attempted clearing the derived data and I attempted re-installing the pods, but it didn't help.
File structure for the relevant files if it helps:
- ESPProvisionSample
- Provision
- ConnectViewController.swift // this is where 'import ESPProvision' is called and not found
- Pods
- Pods
- ESPProvision
EDIT:
I've also now tried to build the ESPProvision module separately by going to Product -> Scheme -> New Scheme and selecting ESPProvision, it built successfully but when I built the main project it once again gives me the same error as above.
Also for clarity yes I am running the project using the generated .xcworkspace file
It seems maybe the framework is missing from ESPProvisionSample -> Frameworks folder, could it be that?
I'm closing this question, it was an issue with the library itself. I opened a ticket with Espressif and they updated their code https://github.com/espressif/esp-idf-provisioning-ios/issues/57

Build error. Installing Firebase in Xcode iOS app with multiple targets and NotificationServiceExtensions

I'm trying to integrate Firebase (for Dynamic Links) in my current Xcode iOS project but I have problems with errors in the build (Following this documentation: https://firebase.google.com/docs/dynamic-links/ios/receive).
My Podfile looks like this:
# Uncomment the next line...
# platform :ios, '9.0'
target 'AppName1' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for AppName1
pod 'Firebase/Analytics'
pod 'Firebase/DynamicLinks'
end
target 'NotificationServiceExtension' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for NotificationServiceExtension
pod 'Firebase/Analytics'
pod 'Firebase/DynamicLinks'end
(... With more targets ...)
TEST1. When I try to complile the App target, this is the errors I am getting:
Error1 Image
'FirebaseCore/FirebaseCore.h' file not found
Firebase.h
While building module 'Firebase' imported from */AppDelegate.h:1.1:
In file included from <module-includes>:1:
Could not build module 'Firebase'
AppDelegate.h
In the file included from */ViewControllerLogin.m:9:
In the file included from */ViewControllerLogin.h:10:
TEST2. If I remove the "pod 'Firebase/ ..." lines from the NotificationServiceExtensions I get these errors:
Error2 Image
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
'openURL:' is unavailable: not available on iOS (App Extension)
TEST1. If I comment the "use_frameworks!" with #, I get the first errors again.
TEST2. If I comment everything inside the targets NotificationServiceExtensions I get:
Library not found for -lFirebaseCore
For every test I'm doing "pod deintegrate" and "pod install" again, open the PROJECT-NAME.xcworkspace, clean and build.
I don't know what else to try or what I'm doing wrong... (the integration with android was super easy...)
Thanks.
Try this:
target 'AppName1' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for AppName1
pod 'Firebase/Analytics'
pod 'Firebase/DynamicLinks'
target 'NotificationServiceExtension' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for NotificationServiceExtension
pod 'Firebase/Analytics'
pod 'Firebase/DynamicLinks'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
CocoaPods docs
Firebase Dynamic Links is not currently supported in extensions.
File an issue at https://github.com/firebase/firebase-ios-sdk to request for consideration.
The problem was related to xcode not building the pods target with the app target.
The correct configuration in the pods file was including the "pod 'Firebase/Analytics' pod 'Firebase/DynamicLinks'" only in the target apps and not in the target Extensions (TEST2 in the question).
After executing "pod update" or "pod install" and opening the correct "your-project.xcworkspace" the answer was to go to Build Settings of the Pods parent Target and set the setting "Build Active Architecture Only" to "No" (Every time a pod is updated, this setting returns to "Yes" in Debug mode). With this, the Pod Target gets build alongside the App Target.

iOS - watchOS App publishing issue CFBundleIdentifier collision

After the app uploading I receive the following email
We identified one or more issues with a recent delivery for your app,
XXX. Please correct the following issues, then upload again.
ITMS-90806: CFBundleIdentifier collision - Each bundle must have a
unique bundle identifier. The bundle identifier
'org.cocoapods.CocoaLumberjack' is used in the bundles
'[CocoaLumberjack.framework, CocoaLumberjack.framework]'
CocoaLumberjack is a third party library that I've already used in the past a lot of times without any problem, I am pretty confused.
It is not related to the framework's .plist keyword CFBundlePackageType
as it is specified in this question/answer Framework CFBundleIdentifier Collision. The CocoaLumberjack bundle package type is "Framework" (CFBundlePackageType = FMWK). CocoaLumberjack is a wide used third party library added to my project using cocoapods.
The issue is probably related to the watchOS target in my app bundle.
The CocoaLumberjack library is used in both iOS app and watchOS app and it is causing the issue about the bundle identifier duplication.
CFBundleIdentifier collision is detected by Apple Connect server if sharing framework between iOS target and Watch Extension.
target 'App' do
platform :ios, '9.0'
# Pods for App
...
pod 'CocoaLumberjack/Swift', '~> 3.5.3'
...
end
target 'AppWatch Extension' do
platform :watchos, '5.0'
# Pods for Watch Extension
...
pod 'CocoaLumberjack/Swift', '~> 3.5.3'
...
end
The iOS app is using the library and the watchOS extension is using the same library. They are using different libraries but CocoaLumberjack is the only one present in both.
I have already published my app a lot of times in the past without any issues with the same libraries configuration. I guess that the Apple has changed some constraints about bundle identifier in the last few days.
The same issue is present also using Carthage.
As a temporary workaround I have manually renamed the bundle identifier in the watchOS extension then the app publishing is working fine but it does not look like a nice solution, especially if you are running the build on a CI system.
A better option is to add a specific post install operation in pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'CocoaLumberjack-watchOS'
target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
end
end
end
end
or if you have to handle multiple libraries:
post_install do |installer|
watchosLibs = ['Lib1-watchOS', 'Lib2-watchOS', 'Lib3-watchOS']
installer.pods_project.targets.each do |target|
if watchosLibs.include? target.name
target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}.${PLATFORM_NAME}"
end
end
end
end
Pay attention to rename pods bundle identifier because some libraries don't behave correctly otherwise.
I suggest to rename only the libraries rejected by Apple in order to minimize the possible issues.
Currently there are some different open threads about this issue:
On Apple forum (currently no more available)
On Cocoapods github project
A similar issue is present also using Carthage instead of Cocoapods
On Carthage github project
If Apple will not change this new policy about bundle identifier then a more clean solution will probably come from cocoapods team.
Apparently Apple changed the validation process. It looks like they don't allow to platform specific frameworks within an app to have the same identifier.
There's a post on the forum about this as well: https://forums.developer.apple.com/thread/122048
If you're running into this issue because you're using Cocoapods you could patch your Podfile to append the Platform Name to the bundle identifier so that they'll be always unique (source):
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
end
end
end
If you have multiple targets in your app you can change the watchOS targets in your scheme in XCode and append .watchos to the identifier as well.
You don't need to change every target, its cleaner to write something like this:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.platform_name == :watchos
target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
end
end
end
end
Here is how I've worked around the problem for Carthage.
1) create a Carthage build script that separates out the different Carthage build phases
2) when you do the actual framework builds; first build the problem frameworks for iOS (I only had one), then modify your project files to change the bundle identifier, then build those frameworks for watchOS, then build the rest of your frameworks
carthage bootstrap --no-checkout
carthage checkout
#undo previous CFBundleIdentifier changes
sed -i '' 's/com.someco.MyFramework.watchOS;/com.someco.MyFramework;/g' Carthage/Checkouts/MyFramework/MyFramework.xcodeproj/project.pbxproj
carthage build --cache-builds --platform iOS
#set a unique CFBundleIdentifier
sed -i '' 's/com.someco.MyFramework;/com.someco.MyFramework.watchOS;/g' Carthage/Checkouts/MyFramework/MyFramework.xcodeproj/project.pbxproj
carthage build --no-use-binaries --platform watchOS --configuration $CONF $VERBOSE MyFramework
One option is - you can add ".watchos"(abc.asd.alomofire.watchos) to the watch bundle identifier manually.
Just remove the embed frameworks build phase from your extension.
Click on extension in target section -> Build phases -> remove the embed pods frameworks
See attached picture:

Can't import dependency installed with Cocoapods

I've installed FBSDK with Cocoapods but can't import it in my AppDelegate.swift file for some reason. The FBSDK kit appears in my Xcode project so I feel like it should be working.
I'm not an iOS developer by any means, I'm just trying to write a simple native plugin for Flutter SDK. Anyone an idea?
--Here is what the pod file looks like--
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
if ENV['FLUTTER_FRAMEWORK_DIR'] == nil
abort('Please set FLUTTER_FRAMEWORK_DIR to the directory containing Flutter.framework')
end
target 'Runner' do
use_frameworks!
# Pods for Runner
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
# Flutter Pods
pod 'Flutter', :path => ENV['FLUTTER_FRAMEWORK_DIR']
if File.exists? '../.flutter-plugins'
flutter_root = File.expand_path('..')
File.foreach('../.flutter-plugins') { |line|
plugin = line.split(pattern='=')
if plugin.length == 2
name = plugin[0].strip()
path = plugin[1].strip()
resolved_path = File.expand_path("#{path}/ios", flutter_root)
pod name, :path => resolved_path
else
puts "Invalid plugin specification: #{line}"
end
}
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
---EDIT---
I''m getting the following error atm: FBSDKCoreKit.framework: No such file or directory.When I open the Frameworks folder in xCode, all file names are in red:
But that exact folder in Finder is empty. So I guess that's why the error is showing. The question is how to fix this...
This is what my embedded binaries and linked frameworks and libraries look like in the project:
Select your Project Target
Go to Build Settings.
Search for Header Search Paths.
Add this value $(SRCROOT)/Pods with recursive, then Xcode will resolve the path for you.
Are you opening the .xcodeproj or the .xcworkspace? Make sure it is the workspace whenever you install a cocoapod
I'll naively suppose you don't have use_frameworks! in you Podfile. If that's true, than you have two ways to go from here:
In your Runner-Bridging-Header.h add #import <FBSDKCoreKit/FBSDKCoreKit.h>, remove import FBSDKCoreKit from AppDelegate.swift and just continue writing the code.
Add use_frameworks! to your Podfile and run pod install again. That might bring some other issues, but if that works, than I'd suggest it.
If you use cocoapods, it should have generated a *.xcworkspace file for you. Open this file instead so your project can see the FBSDK installed and has reference to it.
When you install your pods, you must build your application first. Then your imports stop showing errors.
Why not simply use the Swift pods?-
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
and then import as normal, like-
import FBSDKLoginKit
import FacebookLogin
Once done, do a clean and build (command/⌘ + Shift + K) and Build (command/⌘ + B). Make sure you are using the .xcworkspace file to open the project.
More info on Swift FBSDK here.
Once you use the Swift pods, you should see these Frameworks in your project.
If you still continue to see the error then "Clean the build folder" using command + shift + alt + K.
Start by cleaning your project using Command + Shift + K then close the project and delete the pods folder and the pod.lock file and your .xcworkspace file. Then run pod install and see if that fixes the issue.
First Clean your project directory. And add $(inherited) in framework search path in Build settings.
As importing the FBSDKCoreKit.framework etc. will be performed in the [CP] Embed Pods Frameworks build phase when using CocoaPods, you should remove the references to these frameworks in the Embed Frameworks build phase.
CocoaPods will not create those references, I assume you have tried other ways of importing the Facebooks frameworks, and these link have been created in the process. You can also delete the references to the Facebook frameworks in the Frameworks Folder of you App-Project (the ones in your screenshot written in red, not the ones in the Pods-Project!), but keep the Pods_Runner.framework there.
From what I can tell, your Linked Frameworks and Libraries section looks valid.
If it still doesn't work, I'd advise you to create a new Xcode Project with an empty Podfile, and only include the Facebook frameworks via CocoaPods. Importing the Facebook-SDK in the AppDelegate should work then, otherwise I can share a sample project with you. Then you should check your build setting and build phases, maybe something is wrong there. If you still can't figure out the problem, you will probably need to re-create you xcode-project and import all your files again.
Without a sample Project that reproduces the error, that's the best advise I can give.
Good Luck! :)
The above solutions for Header Search Path should work.
If you are too lazy to go there.
Copy podfile content, remove all pods, pod install, then revert your podfile, pod install again.... Should work ;-)
In my case, it was correctly installed but I realized the pod is Objective-C and couldn't import it on a Swift file. I had to create a bridging header to make it work.
Refer to this stackoverflow thread
How to import existing Objective C classes in Swift

dyld: Library not loaded: error when running on iphone device

Recently I upgrade xcode to 8.0. Since I am using swift2 when I load my previous project xcode will prompt a dialog to migrate my current code to swift2.3. After doing this, my project failed to run on the iphone device. It works fine on simulator. Below is the error I got when running on a device.
dyld: Library not loaded: #rpath/Alamofire.framework/Alamofire
Referenced from: /var/containers/Bundle/Application/29C6F6B8-4CFB-4D1D-864E-45FF6AB13971/cooltoo_go2nurse_ios.app/cooltoo_go2nurse_ios
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/29C6F6B8-4CFB-4D1D-864E-45FF6AB13971/cooltoo_go2nurse_ios.app/Frameworks/Alamofire.framework/Alamofire: code signing blocked mmap() of '/private/var/containers/Bundle/Application/29C6F6B8-4CFB-4D1D-864E-45FF6AB13971/cooltoo_go2nurse_ios.app/Frameworks/Alamofire.framework/Alamofire
I have searched the similar error and tried below suggestions but none of them solve my problem.
In build phase, I added "Copy Files" phase then add Alamofire.framework with Frameworks as the destination, then checked 'Code Sign Copy'.
Set $(inherited) #executable_path/Frameworks on Runpath Search Paths in Build Settings.
In General tab, add Alamofire.framework in Embedded Binaries.
Below is my Podfile:
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'cooltoo_go2nurse_ios' do
pod 'IQKeyboardManager', '4.0.5'
pod 'IQKeyboardManagerSwift', '4.0.5'
pod 'MJRefresh'
pod 'SDWebImage', '~>3.7'
pod 'MBProgressHUD', '~> 0.9.2'
pod 'Alamofire', '3.5.0'
pod 'CryptoSwift', :git => "https://github.com/krzyzanowskim/CryptoSwift", :branch => "swift2"
pod 'Pingpp', '~> 2.1.4'
use_frameworks!
end
target 'cooltoo_go2nurse_iosTests' do
end
target 'cooltoo_go2nurse_iosUITests' do
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end
Does anyone know how to fix this issue?
Thanks
I second this. Here is what I know so far. There seems to be a signing issue. My issue with this was preceded by a ridiculously slow COPY PODS script, looking at the console I was seeing signing errors all over the place. I logged into a fresh account on my computer and was able to get things running right again. Once I logged back into my original account everything came to a screeching halt. I've tried blasting my keychain, re-installing everything imaginable, and nothing is working thus far. I'm on the 8.1 GM, which is when this all started.
--- Edit 10/26/16
I determined that this was a corruption of my signing certificates in combination with something wrong with the keychain, or changes to the keychain being registered with the system. In order to fix this I did a clean install of macOS and restored my files through iCloud rather than from a time machine backup.
I still don't know what caused it but I do know that even with my keychain completely deleted and NO certificates on my computer that Xcode was installing and trying to run on the device. Ultimately the error means that the code is not properly signed so it won't allow the library to be copied and run.

Resources