I am writing an app for my iPad running 3.2.2 with XCode 3.2.3. It seems that the highest version of the iOS for iPad this version of XCode has is 3.2, but other apps load fine onto the phone so this doesn't seem to be an issue. I am attempting to make use of the new UITextChecker class. I have imported UIKit, and UITextChecker.h appears in the headers folder under the UIKit.framework icon. However, when I try to compile this code:
NSString *theLanguage = [[UITextChecker availableLanguages] objectAtIndex:0];
or simply this:
UITextChecker *textChecker;
XCode tells me that UITextChecker is undeclared. Any ideas what it going on here? Thanks!
James
Here is a picture of the UIViewController's header file:
For whatever reason, UIKit.h does not import UITextChecker.h. You can fix this by also adding the following line.
#import <UIKit/UITextChecker.h>
Related
In my Swift 2 project, targeting iOS 9.2 and above, in Xcode 8.2.1, I have code that shows the mail-compose screen like so:
if MFMailComposeViewController.canSendMail() {
let composeMailVC = MFMailComposeViewController()
composeMailVC.mailComposeDelegate = self
composeMailVC.setSubject("Test")
// etc
}
Originally I had a reference to the MessageUI.framework in my project properties, but after removing the framework reference and cleaning the project, it still builds fine and when I run the code on my device the mail compose window still appears and seems fully functional.
I cannot find any explicit references to MessageUI.framework in the raw text of my .xcodeproj file, nor is there anything in my Objective-C bridging header.
I know that Swift does make some implicit framework references, but I couldn't find anything that suggests MessageUI.framework is one of them.
Curiously when I jump to the definition of MFMailComposeViewController XCode shows it in the MessageUI module.
The compiler automatically added the frame work in given its previous direction - IE. Import.
Hi
I am using SDK 4.1 to build an iPhone app and I set the target OS to 3.1.3.
When I install the app on devices running iOS4.1. everything goes smoothly.
When I try to run the app on devices running 3.1.3 I get the stacktrace below.
dyld: Symbol not found: _OBJC_CLASS_$_UINib
Referenced from: /var/mobile/Applications/BDD67A1E-9B40-43E7-A012-7D92036B2E24/ThisIsMy.app/ThisIsMy
Expected in: /System/Library/Frameworks/UIKit.framework/UIKit
in /var/mobile/Applications/BDD67A1E-9B40-43E7-A012-7D92036B2E24/ThisIsMy.app/ThisIsMy
My guess is that it's because UINib was only added to the SDK in 4.0.
What I would like to know is how you mitigate this problem. What should I do to support 3.1.3?
Cheers..
I strongly recommend you not weakly link UIKit. This may hide future linker issues and result in crashes. I'm also simply not comfortable with telling the linker that UIKit is optional when it plainly isn't. Big hack.
Instead, initialize and call UIPopoverController indirectly using NSClassFromString:
Class popover = NSClassFromString(#"UIPopoverController");
if (nil != popover)
{
self.myPopover = [[popover alloc] initWithContentViewController:myContent];
}
If you still have linker errors, you may need to call UIPopoverController's messages using NSSelectorFromString:
Class popover = NSClassFromString(#"UIPopoverController");
if (nil != popover)
{
SEL myInit = NSSelectorFromString(#"initWithContentViewController:");
self.myPopover = [[popover alloc] performSelector:myInit withObject:myContent];
}
For portability, I recommend writing a proxy object to handle these implementation details.
First, you need to change the framework reference to a weak link (aka "optional"). Then use the techniques described here to test that a class exists before calling your code that uses it.
well to begin with I'm sure this is a simple question.
I am developing an iPhone app with the iAd Framework, which only runs for iOS 4.0 or higher.
Still, I wanna choose a iPhone OS 3.0 deployment target, which causes everything to crash.
How do I conditionally include the iAd framework?
...I mean, it would be something like:
...if([[UIDevice currentDevice] systemVersion]>=4.0]) #import
Obviously this won't work because I don't know the correct syntax. Also:
How do I conditionally declare an AdView* variable?
How do I conditionally handle this AdView* variable in my implementation file.
If you guys could help me, I will be very well impressed.
Thanks
You don't need to change your include, you need to make the iAd (or any other new framework) linked weakly:
In your target, find iAd in the linked frameworks and change its "Role" from "Required" to "Weak".
To handle the variable conditionally, use NSClassFromString function, like this:
Class AdClass = NSClassFromString(#"ADBannerView");
if(AdClass) {//if the class exists
ADBannerView* myAd = [[AdClass alloc] initWithFrame:CGRectZero];
// do something with the ad
}
If OS is older than iOS 4.0, AdClass will be nil and the code won't execute. Note that using ADBannerView* as the type of the variable shouldn't cause any problems, as it's just a hint for a compiler and is the same as id after compilation.
Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.
I'm trying to use this class as
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
And getting this compiler error
error: AVAudioPlayer.h no such file or directory
I have added #import "AVAudioPlayer.h at the beginning of the .m file
Could you let me know how can I fix it?
Thanks
Instead of
#import "AVAudioPlayer.h"
Try
#import <AVFoundation/AVAudioPlayer.h>
Add the AVFoundation framework to your project.
The problem is in the fact that as the Fistman said, you probably did not add the Framework to your project.
You need to go to the Frameworks folder (in your project tree on the left side, usually just bellow the Resources folder), right click on Frameworks->Add->Existing Frameworks..' and pick AVFoundation from the list.
Notice that by default XCode will open the frameworks folder of your set Active SDK and so it must be at least OS 2.2 in order to show up (that's the earliest version when apple released it).
Once you added the framework, it should compile and link and you wouldn't have to add the h files manually.
Hope it helped,
-Adi