Swift 'Could not build Obj-C module 'BranchInvite' - ios

I've been following the instructions for implementing this SDK: https://github.com/BranchMetrics/Branch-iOS-Invite-SDK... below is what I have in my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'My-App' do
pod 'BranchInvite'
end
And here is the error I'm getting...
I've done a lot of troubleshooting to try and figure out the problem, looked at past issues of this reporsitory of this sort, and for some reason I cannot get "BranchWelcomeViewController" (nor BranchInvite) to be recognized/imported. Any idea what I'm doing wrong here? Do I need to populate my bridging-header?
PS: I'm using Xcode 7, Swift 2, OS X 10.10.5, and the latest version of Cocoapods.
Thanks

#SamYoungNY, after debugging using the project you sent over, the best approach using Swift appears to be the following:
Podfile
pod "Branch"
pod "BranchInvite"
your app's bridging header
#import <Branch/Branch.h>
#import <BranchInvite/BranchInvite.h>
#import <BranchInvite/BranchInviteViewController.h>
#import <BranchInvite/BranchInviteTextContactProvider.h>
#import <BranchInvite/BranchInviteEmailContactProvider.h>
#import <BranchInvite/BranchWelcomeView.h>
#import <BranchInvite/BranchWelcomeViewController.h>
#import <BranchInvite/BranchWelcomeControllerDelegate.h>
#import <BranchInvite/BranchWelcomeDefaultView.h>
Then be sure to use your project's .xcworkspace file if you weren't previously. Please let us know if this doesn't work. I'm happy to continue to debug with the actual project you sent over.

I received a lot of help from #st.derrick on this question, and there was something wonky with my version control but in the end I got it working with something I found in the branch.io documentation, the answer is in this link:
https://support.branch.io/support/discussions/topics/6000008855

I can't comment yet but here's the archived text from that thread SamYoungNY linked to.
If you're running into an issue where you know that you've imported >Branch, but Xcode can't seem to find it, we may know the answer. You're >probably seeing a screenshot like the one below:
(Picture not archived)
This likely means that you are importing Branch as a "folder reference" >and not a "group".
Delete the Branch folder from your project
Make sure Branch is no longer in your project's folder (in the file >system, not Xcode)
Re-import Branch and be sure to select "Create Groups" (see screenshot >below)

Related

Realm.io build errors when using cocoapods `use_frameworks!`

Goal: Be able to use swift pods in an ObjC project
Steps Taken:
Altered Podfile by appending use_frameworks!
Ran pod install (Cocoapods version 1.0.0)
Built workspace again
Result (Errors):
I get the following Realm.io errors (pod installed from pod 'Realm' since I'm coding in ObjC):
RLMRealm.h:51:1: Duplicate interface definition for class 'RLMRealm'
RLMRealm.h:95:62: Property has a previous declaration
RLMRealm.h:105:38: Property has a previous declaration
RLMRealm.h:110:56: Property has a previous declaration
RLMRealm.h:115:38: Property has a previous declaration
RLMRealm.h:297:28: Property has a previous declaration
RLMRealm.h:493:1: Duplicate interface definition for class 'RLMNotificationToken'
Problem-Solving Steps Taken:
(Previous ones in edit history that led to this simplified question)
Deleted all pods and reinstalled (no effect)
Unlinked Pods framework in Build Phases and relinked (no effect)
Cleaned and built / Cleaned build folder and built (no effect)
Tried importing with "", <>, and #import (currently all imports in my code are done with #import <Realm/Realm.h>) (searched with #import <Realm and #import "Realm) (no effect)
Created new project, copied files over, and pod installed (no effect)
Searched project folder for "#interface RLMNotificationToken" and only found one instance of the RLMRealm.h file, so I don't have duplicates
Deleting all of my files except for AppDelegate.h/m builds successfully
Searched for #import "R, #import <R, #import R and found a rogue #import <RLMRealm.h>
Questions:
I'm frankly really confused and not sure what to do at this point.
So how do I fix these build errors? Why is this happening? Or what other problem-solving steps should I try? (Answers to any of these questions would be appreciated)
Evidently one of my files had a #import <RLMRealm.h> in it (not sure how that got in there). I changed that to #import Realm; and it all works now. I missed that when searching before and only found it while combing my code. Interesting that it works with the library but not with the framework. Well, figured it out and it's all good now.
Realm pod for swift is "RealmSwift". I think you are using objective-c pod.
Have a look at this link Realm for Swift. You can also drag and drop realm framework, this will save from errors you have been facing.
Please check all places, where you import Realm classes. In my case I imported #import <RLMArray.h>. Should be #import <Realm/RLMArray.h>

Import class from development pods with CocoaPods

I get a little older project from another developer and I should fix some issues and add new features. The project is mainly written in ObjC and is using CocoaPods as dependency manager. Previous developer create his own pod in Development Pods and it contains mainly business logic for application. So I needed add some classes there like RCZMortgage. But when I try to use it in main project I get problem:
'RCZMortgage.h' file not found
So I was thinking that I must update pod. So I use command update pod for that one development pod but after that I started have problem with Bridging-Header.h and that files in there can't be found (I don't know if update fix previous problem or just bring more). Previous developer start creating a few classes in swift.
Bridging-Header.h looks like this:
#import "RCZAdvertisementBadge.h"
#import "UIView+Centering.h"
#import "UIColor+CustomColors.h"
#import "UIView+Sizing.h"
#import "SDWebImageManager+AutoScale.h"
#import <SDWebImageManager.h>
#import "RCZImageUrlBuilder.h"
In podfile there is:
platform :ios, '7.0'
but there isn't use_frameworks!
I'm not sure which informations you need to help me. What files should I write here to help me. So any comments and answers are welcome. I can't contact previous developer so I am asking here.
Check weather pod dependencies are correctly matched in build settings.
Give correct pod path, clean the code and try once more.
you should check this tutorial for pod file How to Use CocoaPods
Hope this will help you.

Objective-C class can't import swift pod defined at top level

Here's my Podfile:
platform :ios, '9.0'
use_frameworks!
target :Test_Swift_Import do
pod 'BFKit-Swift', '1.5.1' //Just a swift pod to provide some methods to test
pod 'SwiftySwift', '1.0.1' //and another
end
In my AppDelegate class I try to use a simple method from BFKit
BOOL isEmail = [#"not an email" isEmail];
My AppDelegate is an objective-c class, not Swift
In order to make this work I try to import the BFKit Swift module
First I try the well-known way:
//Basic <Product_Name-Swift.h>
#import <Test_Swift_Import-Swift.h>
But this SO post and this one too both say to use <ProjectName/ModuleName-Swift.h>. Because the code is in a module, this makes sense to me.
So I try #import <Test_Swift_Import/BFKit-Swift.h>
No deal...
I rename my project to TestSwiftImport in case underscores are a problem
No deal...
I try importing the module directly
<BFKit/BFKit.h>
Alas...
Relevant Xcode Build Settings
defines modules : Yes
Product Module name: TestSwiftImport
Enable Modules: Yes
Link Frameworks Automatically: Yes
Objective-C Generated Interface Header Name: TestSwiftImport-Swift.h
Objective-C Bridging Header: TestSwiftImport/TestSwiftImport-Bridging-Header.h
Drastic Things I've Tried
I've done all manner of cleaning project and build folder, wiping derived data, resetting simulator, quitting simulator, quitting Xcode and restarting machine, all to no avail. It's sad that these are even things I think of doing and that they sometimes work... But not in this case.
Github Demo Project Displaying Problem
...is here
Any ideas? There are even more failed attempts that you can see if you open the project. This can't be this hard...
I see that is problem of CocoaPods.
Now If I try drag file straight to xcode it will work normal. If you really need it. You can drag all file to project. Not use cocoa-pods now.
You can reference to this question: Question
Hope this help!

How to get cocoa pods to work?

I have installed cocoapods. I've done everything that I've seen online, yet I can never successfully import a 3rd party framework into my project. I have tried many, many times--at least 20 probably, and have not once been able to successfully do this. Take for example, this library: https://github.com/uacaps/PageMenu
I added the podfile, I ran "pod install", that worked, I opened up the workspace and not the original project, I added the framework under "linked frameworks and libraries." But it still says "No such module Page Menu." It does this for every single pod that I try to install. What am I doing wrong? From what I've read everyone seems to think they are so easy to install. And they are, problem is they just never work once I do install them. Is there some missing step that everyone else knows about that I don't? I have looked under build settings and I've read something about changing the linker flags, but I couldn't figure out how to do that. I have tried installing the library manually and that didn't work either. Could it be that something is just wrong with my Xcode? I've been having this problem for a few months, and it has stayed consistent since I updated my Xcode recently. Does anyone have any idea what this could be?
edit: link to Podfile photo:
http://i58.tinypic.com/2lc2zqb.png
First,make sure that you have something like this in your PodFile (same folder as your xcode proj)
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'PageMenu'
then cd to the directory and do pod install in terminal.
I am assuming that you are using swift. Build the project. Go to your report navigator.
EDIT:: Do open the proj using xcworkspace instead of xcodeproj
You should see something like this.
This tells you what you have to add in your bridging header.
To create a bridging header, create a random objective c file (with cocoa touch class). XCode will ask you if you want to create bridging header.
Select yes, then delete the files you just created. Next, go to the generated bridging header file. Add in
// this header should be based on the name you see in report navigator.
#import <PageMenu/PageMenu-Swift.h>
Look, Calm Down..
I had the same problem.Didnt give up.try doing this as well,worked for me
create new project
close xcode
go to target folder pop init
open -a Xcode Podfile-uncomment platform -pod 'PageMenu' ( I typed this outside target this time/not like the usual way typing it inside target- do/ ,save and close)
open xcodeworkspace and Type - import PageMenu -( still says unresolved module )
Now Build ..
(worked for me, It somehow works with clean or Build i suppose ,so try both)

Google/Analytics.h file not found when adding to AppDelegate

I am trying to integrate Google Analytics in my ios project using Cocoapods. However, after following this for the steps till adding configuration file to my project, when importing the Google/Analytics.h in AppDelegate I get error for file not found. Tried following things:
Added $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings.
Added libGoogleAnalyticsServices.a to link binary with libraries in build phases.
Added -lGoogleAnalyticsServices in Other Linker Flags.
Don't really want to do 2 and 3 as they make it free from Cocoapods.
What exactly am I missing?
Swift 3
With version 3.17.0 (installed using pod 'GoogleAnalytics' in Podfile):
Open yourproject.xcworkspace instead of yourproject.xcodeproj
Use #import <GoogleAnalytics/GAI.h> in the bridging header file
Edit:
Per jeremy piednoel's comment you may also need
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Problems
The code examples on the official documentation suggest
installing 1.0.0. Which doesn't even have binaries compiled for
arm64.
There seem to be at least three separate pods related to
GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.
Solution
Add this to your Podfile: pod 'Google/Analytics' and then pod install.
That should work. Now you can simply import Google/Analytics.h as suggested in the docs:
#import <Google/Analytics.h>
Further Discussion
There were two sets of issues that I ran into:
When using the incorrect suggested pod version (1.0.0), was a 64-bit compatibility issue. (ld: symbol(s) not found for architecture arm64)
When using the other pods (GoogleAnalytics-iOS-SDK and GoogleAnalytics) I had complaints of a missing <Google/Analytics.h> header file. ("Google/Analytics.h" not found)
I found this gentleman's post on a mailing list which suggested the Google/Analytics pod with no version number. (pod 'Google/Analytics' as noted above.)
This is a bug in cocoapods.
you need to add $(SRCROOT)/Pods/Google and $(SRCROOT)/Pods/GoogleAnalytics with recursive option to your User Header Search Paths.
Then include the #import "Analytics.h" instead of #import
When you add $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings, also select recursive option. It will allow your project to search in GoogleAnalytics and all of its sub-directories.
UPDATED:
I have tried the tutorial and it works fine without any extra step. My pod version is 0.35.0. When you create configuration file, remember to enable GoogleAnalytics service.
UPDATED:
As #RajatTalwar pointed out, you also need to add $(SRCROOT)/Pods/Google with recursive option. Then include the #import "Analytics.h" instead of #import
If anyone else out there is having an error with trying to #import <Google/Analytics.h>, and the other solutions online aren't helping you, you should read on.
I was having this problem and none of the solutions I found would fix it. Then I noticed that one of my targets worked while the other one did not (I had two in the same project), and I tried to track down what was the difference between the two targets.
I noticed that there was a difference in the project on the General tab under Deployment info, where the second target (the one which worked) had separate options for iPhone and iPad, but the first did not. Someone else online said that they received these two new options when they duplicated their target. My second target was also a duplicate of the first, originally.
To make a long story short, I found that if I duplicated my target that the duplicate now suddenly worked. Those separate iPhone and iPad options also magically appeared. So I guess my project target was non-standard and causing a problem, probably because this project was created a long time ago.
I then just deleted the original target and renamed the new one to be the same name, although there was some cleanup work required in the build settings related to the plist file (it made a copy.plist file).
Hope this helps someone.
Check if you have multiple targets, in this case add pod 'Google/Analytics' foreach target in you pod file:
def google_pods
pod 'Google/Analytics'
end
target 'target 1' do
google_pods
end
target 'target 2' do
google_pods
end
target 'target N' do
google_pods
end
Also my $0.02 to this, since it seems to be a never ending story. None of the suggestions above did help. I got this obscure message from pod install
[!] The `blabla [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-blabla/Pods-blabla.release.xcconfig'. This can lead to problems with the CocoaPods installation
Finally I inspected my project.pxbprojand found, that I had this entry:
HEADER_SEARCH_PATHS = "";`
Obviously this is treated as "defined", so I changed it to
HEADER_SEARCH_PATHS = "$(inherited)";
and boom - all the Google suggested includes work
#import <GoogleAnalytics/GAI.h>
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Run pod update
Clean Build Files
Run Project
remove valid archs from build settings

Resources