iOS - _OBJC_CLASS_$_CTTelephonyNetworkInfo not found? - ios

I am using the following code to get network info about my iPhone -
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
But I get the error -
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_CTTelephonyNetworkInfo", referenced from:
objc-class-ref in MyClass.o
ld: symbol(s) not found for architecture armv7
Isn't the class a part of the iOS SDK? What am I doing wrong?

It is part of the CoreTelephony.framework. You need to add that framework for your code to work.

I had a similar issue. Mine was related to having multiple targets, where it would fail on only 1 target.
To resolve it I had to ctrl-click the CoreTelephone.framework and select to add it to all my schemes.
The exact error I was getting was "Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CTTelephonyNetworkInfo","

Related

Missing symbols from LayarSDK in the simulator

I'm including the Layar SDK framework into my app (version 8.0) and everything works fine on a device.
However, I can't run the app on a simulator anymore - I don't mind Layar not working (there's no camera after all!) but I do need it to compile for continual integration, automated tests etc (not to mention developing on the train top/from work!)
The linker gives me these errors :
ld: warning: ignoring file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a, missing required architecture i386 in file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a (2 slices)
ld: warning: ignoring file local/LayarSDK/LayarSDK.framework/LayarSDK, missing required architecture i386 in file local/LayarSDK/LayarSDK.framework/LayarSDK (2 slices)
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_LayarSDK", referenced from:
objc-class-ref in MYAppDelegate.o
ld: symbol(s) not found for architecture i386
Checking, the LayarSDK doesn't contain i386, it only contains armv7 and armv7s.
My solution is pretty clumsy - if anyone has a better idea, please let me know!
I compile this file (LayarSimulatorStub.m) into my app :
#if TARGET_IPHONE_SIMULATOR
#import <Foundation/Foundation.h>
#interface LayarSDK : NSObject
#end
#implementation LayarSDK
+ (id)layarSDKWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
- (id)init { return nil; }
- (id)initWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
#end
#endif
Now, there is an i386 symbol LayarSDK. It just returns nil from all it's constructors. The app now compiles with Layar disabled.
The conditional compilation means that it's not present for the device architectures so there are no linker errors.

iOS Undefined symbols for architecture i386: "_kUTTypeImage"

Undefined symbols for architecture i386:
"_kUTTypeImage", referenced from:
-[ViewController receiveNotification:] in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm adding a UIImagePickerController to my app and when I go to compile I get the above error. I found a solution on SO:
Symbol not found: kUTTypeImage
Look up the symbol (kUTTypeImage) and locate the image/library it should exist in (MobileCoreServices.framework in this case). Then link your binary with that framework.
Problem is, I'm not sure how to implement it. How do I look up the symbol and then link it to the framework?
Should of noted I already have the MobileCoreServices framework imported. Here's the relevant code:
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* myCamera = [[UIImagePickerController alloc] init];
myCamera.delegate = self;
myCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
myCamera.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
myCamera.allowsEditing = NO;
[self presentModalViewController:myCamera animated:YES];
}
You only need to add and then import the framework into your project (or rather, target). In the Navigator, click on your project, and select a target. Then go to the Build Phases tab and, if it's not expanded already, expand Link Binary With Libraries. Then add MobileCoreServices.framework. In the file you want to use kUTTypeImage, add this import:
#import <MobileCoreServices/MobileCoreServices.h>
Note that you use angle brackets (<>) and not quotes as you would normally.

Apple Mach-O Linker Error using Core Data classes in OCUnit

OK, here's my code in my test class:
- (NSManagedObjectContext*)managedObjectContextWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType {
NSManagedObjectModel *mom = [NSManagedObjectModel mergedModelFromBundles:nil];
STAssertNotNil(mom, #"Can not create MOM from main bundle");
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
STAssertNotNil(psc, #"Can not create persistent store coordinator");
NSPersistentStore *store = [psc addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:0];
STAssertNotNil(store, #"Can not create In-Memory persistent store");
NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:concurrencyType];
moc.persistentStoreCoordinator = psc;
return moc;
}
And here's the failure message when trying to use the method in a test method:
Undefined symbols for architecture i386:
"_NSInMemoryStoreType", referenced from:
-[CrosswordItemTests managedObjectContextWithConcurrencyType:] in CrosswordItemTests.o
"_OBJC_CLASS_$_NSEntityDescription", referenced from:
objc-class-ref in CrosswordItemTests.o
"_OBJC_CLASS_$_NSManagedObjectContext", referenced from:
objc-class-ref in CrosswordItemTests.o
"_OBJC_CLASS_$_NSManagedObjectModel", referenced from:
objc-class-ref in CrosswordItemTests.o
"_OBJC_CLASS_$_NSPersistentStoreCoordinator", referenced from:
objc-class-ref in CrosswordItemTests.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I thought I imported the needed classes like that in the .h file:
#import <CoreData/CoreData.h>
What am I missing?
In my experience i386 errors tend to come from missing libraries. Its not enough to just #import them in your file, you must also add them to the project libraries. Go into the Project Target -> Build Phases -> Link Binary with Libraries and in your case add the libraries associated with Core Data.
You probably haven't linked the library to the target.
Taken from: http://yannickloriot.com/wp-content/uploads/2012/03/Link-CoreData-Framework-To-The-Project.png
Changing 'No Common Blocks' from Yes to No (under Targets->Build Settings->Apple LLVM - Code Generation) fixed the problem.
This fixed my problem. Hope it will help to you.

Need Reachability version for ARC in iOS5

Using Apple's Reachability code in iOS5 I get a bunch of compilation errors as shown below. Any ideas on what is happening here? I'm using ARC so I have edited the standard code slightly to remove autorelease/retain and the NSAutoReleasePool.
Undefined symbols for architecture armv7:
"_SCNetworkReachabilityCreateWithAddress", referenced from:
+[Reachability reachabilityWithAddress:] in Reachability.o
"_SCNetworkReachabilityCreateWithName", referenced from:
+[Reachability reachabilityWithHostName:] in Reachability.o
"_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
-[Reachability stopNotifier] in Reachability.o
"_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilitySetCallback", referenced from:
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilityGetFlags", referenced from:
-[Reachability connectionRequired] in Reachability.o
-[Reachability currentReachabilityStatus] in Reachability.o
ld: symbol(s) not found for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
Does anyone have workable Reachability code for ARC under iOS5?
I wrote a clean 'drop in' version of reachability for ARC and iOS5 - you can get it here: https://github.com/tonymillion/Reachability
You don't really need an ARC version of Reachability, just simply disable ARC for reachability file(s)
Disable ARC on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
You also have a missing framework. Add SystemConfiguration framework.
I rearranged them for IOS 5 and arc they are working tested
Please DON'T FORGET TO ADD SystemConfiguration.framework on your project
I just found this that might help. Thank the author for this (this is not mine)!
https://gist.github.com/1182373
Apple's reachability has been updated to version 3 which now supports ARC iOS5+
Here is the link to the sample by Apple
You need to add the systemConfiguration.framework to make Reachability work.
I know this thread is old, but in case anyone is interested you can solve this by disabling ARC for Reachability.m. Look at this post.
Tony, is your class correctly work even with a non ARC project?
I can see lot ok Reachability: dealloc in my consolle, and I don't know if it's normal or not!
I use this method to check the connection (is the only place where I user Rechability)
-(BOOL)checkConnection{
BOOL connessione = FALSE;
Reachability *wifiResouce = [[Reachability reachabilityForLocalWiFi] retain];
Reachability *phoneResouce = [[Reachability reachabilityForInternetConnection] retain];
NetworkStatus netStatusWiFi = [wifiResouce currentReachabilityStatus];
NetworkStatus netStatusPhone = [phoneResouce currentReachabilityStatus];
if(netStatusWiFi == NotReachable){
if(netStatusPhone == ReachableViaWWAN){
connessione = TRUE;
}
}else if(netStatusWiFi == ReachableViaWiFi){
connessione = TRUE;
}
[phoneResouce release];
[wifiResouce release];
return connessione;
}

"symbol(s) not found for architecture i386" problem using ShareKit

I want to use the http://getsharekit.com framework for future iOS projects. Hence I started testing out the framework.
But I already get the following error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SHKItem", referenced from:
objc-class-ref in ShareKitTestAppDelegate.o
"_OBJC_CLASS_$_SHKActionSheet", referenced from:
objc-class-ref in ShareKitTestAppDelegate.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Often, as far as I know, these problems arise if header files are wrongly imported. But I don't see any error here in the following code where the problem above occurs:
#import "ShareKitTestAppDelegate.h"
#import "SHK.h"
#import "SHKItem.h"
#import "SHKActionSheet.h"
- (IBAction) letshare:(id)sender
{
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:#"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:#"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[self.window addSubview:actionSheet];
}
I also included the ShareKit Headers Folder into HeaderSearchPath Build-Options, because of searching for all the headers.
But I don't see any error here or anything missed.
Can somebody help me?
With best regards,
Andreas
I had a similar problem with the following linker error:
Undefined symbols for architecture i386: "_OBJC_CLASS_$_SHK"
I resolved it by adding SHK.m to compiled sources under Project settings->Target->Build Phases. Not sure why SHK.m was not in the compiled sources list, and it was working previous to duplicating the Target. After the duplication I couldn't link any of the targets.
Adding SHKItem.m or SHK.m to compiled sources might help you if they aren't there already.
Read this http://getsharekit.com/install/.
Have you added the frameworks?

Resources