Pinterest Linker Error when added through CocoaPods - ios

1)I have did all steps given at Pinterest developer site here
2)This is my pod file
# Uncomment this line to define a global platform for your project
platform :ios, ‘7.0’
# Uncomment this line if you're using Swift
# use_frameworks!
target 'xyz.com' do
pod "PinterestSDK", :git => "https://github.com/pinterest/ios-pdk.git"
end
target 'xyz.comTests' do
end
3)When I run without #import "PDKPin.h" & following code
[PDKPin pinWithImageURL:[NSURL URLWithString:imageUrl]
link:[NSURL URLWithString:shareUrl]
suggestedBoardName:#""
note:productName
withSuccess:^
{
NSLog(#"Succesful to pin");
}
andFailure:^(NSError *error)
{
NSLog(#"Failed to pin");
}];
it runs without error
4)But when I add the above code it gives linker error
Edit: I have tried it in blank project it works fine. But I am unable
to figure out what all the dependencies still there in old project.

Start Fresh
Use Xcode 7.1+, create a new project, run pod install:
target 'SO-34633492' do
pod "PinterestSDK", :git => "https://github.com/pinterest/ios-pdk.git"
end
You probably have inconsistencies in your existing project ; while figuring out what is wrong may be enlightening, may I suggest starting on a clean slate.
Must include headers
You cannot compile your .m without including #import <PDKPin.h>:
~/SO-34633492/SO-34633492/ViewController.m:21:6: Use of undeclared identifier 'PDKPin'
This does work:
#import <PDKPin.h>
NSString * imageUrl = #"";
NSString * shareUrl = #"";
NSString * productName = #"";
[PDKPin pinWithImageURL:[NSURL URLWithString:imageUrl]
link:[NSURL URLWithString:shareUrl]
suggestedBoardName:#""
note:productName
withSuccess:^
{
NSLog(#"Succesful to pin");
}
andFailure:^(NSError *error)
{
NSLog(#"Failed to pin");
}];
Things that may have gone wrong
Compare your projects: https://stackoverflow.com/a/2889730/218152
Delete Derived data: https://stackoverflow.com/a/32859942/218152
Library not found: https://stackoverflow.com/a/31419234/218152
Configuration error: https://stackoverflow.com/a/33509278/218152
Read more: https://stackoverflow.com/search?q=user%3A218152+cocoapod

After a long search & tries
I have found the following solution
I have changed the target's build settings in
the other linker flags section.
I have added the flag $(inherited) in other linker flags

Related

After adding Extension I am getting Lexical and PreProcessor error Xcode 9.3?

Hi all I have added Notification service extension and added target properly . When I build the project I am getting lexical error .
Tried cleaning archive , Restart Xcode , Changing framework path .
If I remove the Notification Service Extension then everything is working , When I am adding the notification extension to my project I am getting this error .
If anyone crossed this issue . Let me know what I am doing wrong .
What I did?
File -> New -> Target -> Notification Service Extension added under project.
Made changes on the extension class file.
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
NSString *imgUrl = request.content.userInfo[#"data"][#"attachment-url"];
NSURL *imageURL = [NSURL URLWithString:imgUrl];
NSError *error;
UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:#"image" URL:imageURL options:nil error:&error];
if (error)
{
NSLog(#"error while storing image attachment in notification: %#", error);
}
if (icon)
{
self.bestAttemptContent.attachments = #[icon];
}
self.contentHandler(self.bestAttemptContent);
If you are using cocoa pods, Edit your pod file, and create two types of pods, one for main target application, one for extension target.
def application_pods
use_frameworks!
#list of frameworks you use in your main target
pod 'UIImageView+WebCache'
end
def extension_pods
use_frameworks!
#list of frameworks you would use in your extension
pod 'UIImageView+WebCache'
end
target 'YourMainTargetName' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
# Pods for YourTargetName
application_pods
end
target 'NotificationService' do
extension_pods
end
If you dont use pods, then you need to select the UIImageView+WebCache .h,.m files and in the Target membership section, you need to check the extension target checkbox.
Finally:
The issue is because of the created extension carrying the header path as Parent file header path , So if you mentioned any pod file header path in you prefix then it will give you the error , So remove the header path and kept it as empty .
Build Setting -> HeaderPath -> Remove it .
Make sure you have selected the extension target while removing the path .

Linking to J2ObjC from another CocoaPod

We use J2ObjC and are trying to make the switch to Xcode 6's dynamic frameworks in order to incorporate Swift into the project. Simply adding use_frameworks! to our Podfile works great in the case where we're just using J2ObjC, but the problem comes when adding other libraries that reference it.
In this particular example, I have two pods in my Podfile, J2ObjC and any other pod that uses it. Let's call it whatever. The current J2ObjC podspec can be found here. Here's the podspec for whatever:
Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'
s.requires_arc = true
s.source_files = '**/*.{h,m}'
s.dependency 'J2ObjC'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/J2ObjC/dist/include',
'LIBRARY_SEARCH_PATHS' => '${PODS_ROOT}/J2ObjC/dist/lib' }
end
So far so good. Now, if I want to reference a Java class, say JavaUtilArrayList inside my app, I can do that.
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
JavaUtilArrayList *arrayList = [[JavaUtilArrayList alloc]init];
NSString *whatever = #"o hai";
[arrayList addWithId:[whatever copy]];
NSLog(#"%#", arrayList);
}
Awesome, J2ObjC works inside my main target. But if I try to do the same thing inside whatever, even though the compiler thinks everything is fine (J2ObjC imports work, classes are available, etc.), I get a linker error:
#import "SomeClass.h"
#import "java/util/ArrayList.h"
#implementation SomeClass // Inside 'whatever'
-(JavaUtilArrayList *)arrayList {
NSString *aThing = #"o hai";
JavaUtilArrayList *myList = [[JavaUtilArrayList alloc]init];
[myList addWithId:aThing];
NSLog(#"%#", myList);
return myList;
}
leads to:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_JavaUtilArrayList", referenced from:
objc-class-ref in SomeClass.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've been going crazy reading the CocoaPods guides, man ld, and the J2ObjC guides and am still not getting anywhere. Has anyone built a pod on top of J2ObjC and successfully installed it using use_frameworks!? Any advice would be super appreciated.
Any symbol begging with "_OBJC_CLASS" is from J2ObjC. If it begins "_OBJC_CLASS_$_Java" then it's from the Java Runtime Environment (JRE). If it doesn't have "$_Java" then see this answer.
The linker is missing out the libjre_emul.a library from J2ObjC (JRE emulation library). You need to configure the following:
LIBRARY_SEARCH_PATHS: J2OBJC_HOME/lib
OTHER_LDFLAGS: -l"jre_emul"
I'd suggest trying out the J2ObjC Gradle Plugin as it will automatically configure this for you. Alternatively, see the Xcode Build Rules.

Ensembles in iOS swift

I would like to use Drew McCormack's Ensembles from github to relieve my current iOS/swift/coredata/iCloud induced headache. All of the Ensembles examples are in Objective-C. I have it as a Framework in my project, but being a weekend coder, I can't extrapolate how to use it from the ObjC example code.
Has anyone seen a How-To for Ensembles using swift?
Adding: I have it as a framework, but how do I set it up and have it start Leeching? The Obj-C way is to
//SetupEnsemble
cloudFileSystem=[[CDEICloudFileSystemalloc] initWithUbiquityContainerIdentifier:#"container"];
ensemble=[[CDEPersistentStoreEnsemblealloc]initWithEnsembleIdentifier:#"MainStore" persistentStoreURL:storeURL
managedObjectModelURL:modelURL
cloudFileSystem:cloudFileSystem]; ensemble.delegate=self;
and then Leech
if(!ensemble.isLeeched){
[ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
if (error) NSLog(#"Could not leech to ensemble: %#", error); }];}
The following steps describe how you add ensembles with the iCloud + Dropbox filesystem to your project:
Add a 'Podfile' to your project with this contents:
target :YOUR_TARGET_NAME do
platform :ios, '7.0'
pod "Ensembles", :git => 'https://github.com/drewmccormack/ensembles.git'
pod "Ensembles/Dropbox", :git => 'https://github.com/drewmccormack/ensembles.git'
link_with 'YOUR_TARGET_NAME'
end
Run 'pod install' from your terminal
Create a ObjC bridging header
Add Ensembles (and other frameworks to the bridging header):
#import <Foundation/Foundation.h>
#import <Ensembles/Ensembles.h>
#import "DropboxSDK.h"
#import "CDEDropboxCloudFileSystem.h"
Happy coding:
var ensemble:CDEPersistentStoreEnsemble?
var ensembleFileSystem:CDECloudFileSystem?
ensembleFileSystem = CDEICloudFileSystem(
ubiquityContainerIdentifier: "SOME_CONTAINER",
relativePathToRootInContainer: "STORE_ROOT_PATH"
)
ensemble = CDEPersistentStoreEnsemble(
ensembleIdentifier: "IDENTIFIER",
persistentStoreURL: "STORE_URL",
persistentStoreOptions:nil,
managedObjectModelURL:"MOM_URL",
cloudFileSystem:ensembleFileSystem,
localDataRootDirectoryURL:"DATA_ROOT_URL"
)
e.leechPersistentStoreWithCompletion({ (error:NSError?) -> Void in
// check for error, etc...
})
If you're a weekend coder I would recommend using Apple's CloudKit. It's all in swift, of course. There are are some good tutorials at: https://videos.raywenderlich.com/courses/45-introduction-to-cloudkit/lessons/1

Unable to integrate ZXingObjC in a iOS Swift Project

Im working on an iOS project, which shows the customer number in a barcode. I had installed the framework ZXingObjC with CocoaPods, described in GitHub.
I can compile my Project without errors. I can also use the classes of ZXingObjC in my Objective-C classes, without errors. After than, I have added the import Command #import <ZXingObjC/ZXingObjC.h> to my bridging header file, like my other custom objective-c classes, without compile errors. (I had testet the header file by destroying some import statements and got the expected file not found exception.)
But now, I can't use any class of ZXingObjC in my swift classes. I only got the following compile error: Use of undeclared type '...'. The Xcode autocomplete is not working, too.
e.g.
var test : ZXMultiFormatWriter?
>> Use of undeclared type 'ZXMultiFormatWriter'
I tried:
setup new project, same issue
checked header search path: $(SRCROOT)/Pods/Headers/Public/Adjust
reinstalled the ZXingObjC framework
checked build settings: Enable Modules: YES
checked build settings: Other Linker Flags: $(inherited) -ObjC
-framework "ZXingObjC"
checked linked binaries in the build phases: framework is added
checked import statement in the bridging header file (#import
<ZXingObjC/ZXingObjC.h> and #import "ZXingObjC/ZXingObjC.h" -- no
difference)
Windows style: restarting Xcode and Mac ;-)
I'm using:
Xcode: 6.3.2
CocoaPods: 0.37.2
Project Deployment target: iOS 8.0
SDK: 8.3
Does anyone know the problem? Can anyone help?
How can I make the ZXingObjC framework available in swift?
Actually it is an easy issue:
Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'ZXingObjC', '~> 3.1'
So, on terminal:
cd workspace
pod install
Then, once opened project on Xcode, you have to edit bridging-header adding ZXingObj:
#import <ZXingObjC/ZXingObjC.h>
Finally, in your swift classes that uses ZXingObjC, you have to import ZXingObjC.
import ZXingObjC
class ZXingObjCWrapper {
func encode() {
let writer = ZXMultiFormatWriter.writer()
....
}
}
The rest of the code for when you need to set an UIImage with this bar code:
func generateDataMatrixQRCode(from string: String) -> UIImage? {
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
if let imageRef = ZXImage.init(matrix: result) {
if let image = imageRef.cgimage {
return UIImage.init(cgImage: image)
}
}
}
catch {
print(error)
}
return nil
}
The header search path was not correct in my project. The right values are:
$(inherited)
"${PODS_ROOT}/Headers/Public"
"${PODS_ROOT}/Headers/Public/ZXingObjC"
The second and third lines were not added by installation with CocoaPods.
EDIT: The installed framework have to be added to "Embedded Binaries" in General tab of the project.
I tried everything on this page to add ZXingObjC as a Pod. My goal was to generate an Aztec barcode.
I checked my Header Search Path. As Reddas said, I had to manually add "${PODS_ROOT}/Headers/Public/ZXingObjC". I also added ZXingObjC as an Embedded Binary (in the General Tab).
I checked my bridging file & all was good. I checked my view controllers where I wanted to generate the barcode. The import ZXingObjC was there.
No compile errors. But I can't declare a variable of ZXingObjC.
No luck. Any more suggestions?
EDIT - I went into the Targets, Build Settings and searched for Header Search Paths. I added in BOTH "${PODS_ROOT}/Headers/Public/ZXingObjC" and "${PODS_ROOT}/Headers/Private/ZXingObjC"
This seemed to unclog whatever broke. It works now. Strangely, I can now even delete those entries and it works.

Google Cloud Endpoints linking iOS client issues

This problem arises from the fact I don't completely understand static libraries in iOS and the docs from google seem to be a little sparse.
I am trying to use Google Cloud Endpoints for my mobile backend.
I generate the .m and .h files for my client library. Then I created a new project(OwnItApi), dragged the libGTLTouchStaticLib.a static library from GTL.proj to this new project. Then I add the generated files .m and .h files to this project. I add all the .m files to the Compile Sources and then I the header files Copy Files. In the Build Settings I add "-ObjC -all_load" to the Other Linker Flags item.
Update: I forgot to mention that I also copied the headers from the GTL.proj to OwnItAPI project. These include files GTLBase64.h, GTLBatchQuery.h, GTLBatchResult,h, etc. I think I had to do this because the build was failing without them.
Without the headers, I get: the error "'GTLObject.h'file not found." on the import statement.
Then I take the static library generated from this project and add it to my main project whose target is an iphone app. To test if the API is working, I added this to App Delegate
#import "OwnItApi/GTLServiceOwnit.h"
#import "OwnItApi/GTLQueryOwnit.h"
#import "OwnItApi/GTLOwnitApiBrands.h"
This is inside the application:didFinishLaunchingWithOptions: function
static GTLServiceOwnit *service = nil;
if (!service) {
service = [[GTLServiceOwnit alloc] init];
service.retryEnabled = YES;
[GTMHTTPFetcher setLoggingEnabled:YES];
}
GTLQueryOwnit *query = [GTLQueryOwnit queryForBrandsListWithUserID:#"venkat"];
[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLOwnitApiBrands *object, NSError *error) {
NSArray *items = [object brands];;
NSLog(#"%#", items);
}];
When I compile I get duplicate errors like this:
duplicate symbol _OBJC_METACLASS_$_GTLOwnitApiBrand in:
/Users/vrao/Library/Developer/Xcode/DerivedData/Own_It!-ertvnctptaddricdrjyrmgemzgsh/Build/Products/Release-iphoneos/libOwnItApi.a(GTLOwnit_Sources.o)
17 errors that look just like that. and then finally
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Update: In GTL project, libGTLTouchStaticLib.a is red after I build it and when I right click it the "Show in Finder" is greyed out. To find the .a file I use "Show in Finder" for "GTL.framework" and then go back a folder to find libGTLTouchStaticLib.a.
I believe you're seeing the issue you see because you're also including the GTLOwnit_Sources.m file. You can omit this from the list of files you include.

Resources