UIGraphicsBeginImageContextWithOptions undeclared - iphone

Greetings!
I'm attempting to build an iPhone application that makes use of an iOS4-only function: 'UIGraphicsBeginImageContextWithOptions'.
I'm building for iPhone device 3.1.3 in XCode 3.2.1 and getting errors about that function not being defined.
This stackoverflow page already showed me that I should link weakly against UIKit and check that function for NULL, I am already doing this:
However, build still fails with:
Anyone have any idea?

You need to build against the iOS 4.x SDK, otherwise the compiler has no knowledge of that function.

Related

Swift Compiler error: During the test the app in the iphone device

I want to test my project in an iPhone device, but when I connected my device to system and run the app an error occurs. The error is like that Swift Compiler error:
cannot underlie module for 'CoreGraphics'
I am using Xcode 6.1.1 and swift language to develop apps.
I already provide same Bundle identifier in info. list and where required.
When I want to add the CoreGraphics framework from the Link frameworks and library option in Project Navigator this will not show this framework in the list.
I don't know where I am going to run..
Sometimes the Xcode is deleted unfortunately frameworks like UIKIt and CoreGraphics etc..
So i do re-install the Xcode 6.1.1 then these error is fixed...

UIInterfaceOrientationMaskAllButUpsideDown showing error while making a build

I am making an app having deployment target 4.3, but my base SDK is 6.0.
Now when I make build then the compiler is showing error about usage of UIInterfaceOrientationMaskAllButUpsideDown.
that symbol isnt defined in 4.3 and so it doesnt work :)
ios6 changed how VCs tell it about supported rotations
implement the old way using shouldAutorotate:

SeckeychainItemref undeclared

When I am integrating MGTwitterEngine in my app, this error is coming:
"SeckeychainItemref" undeclared
Can anyone tell how to resolve this?
I had similar problem while building OAuthConsumer for iOS - I removed unwanted Mac specific key-chain files .h/.m and I can build it on iOS.
SeckeychainItemref is not available in the iOS SDK.
As far as I know, its only used, for testing in the iPhone simulator. (if you found it in the code for a iOS app)
If it isn't for iOS, then you should add the Security framework and import Security/Security.h in your code.

NSXMLParserDelegate and iPhone SDK 3.1.X

I have an app on the store which was built for 3.1.2, but which was crashing under 4.0GM. I've fixed the crash problem using Xcode 3.2.3, but was also getting warnings that such-and-such class did not implement NSXMLParserDelegate. I added to the headers and everything seemed fine. I've now submitted the app and it's waiting for review. This latest version was compiled with base SDK of 4.0, and a deployment target of 3.1.2.
The problem I have is that this morning I opened up the project in Xcode 3.2.2, and when building against base SDK of 3.1.2, I'm getting compile errors saying that NSXMLParserDelegate does not exist. Does this mean my app that is waiting for review is going to crash under 3.1.2 devices? This is strange, because my beta testers who are using 3.1.3 and I think 3.1.2, said the app works fine. Shouldn't it crash if it can't compile against base SDK of 3.1.2?
I think this should be ok to discuss in regards to the 4.0 NDA, as my problem is specific to 3.1.X.
First of all, the NDA has been lifted this week, so no problem to discuss the iOS 4.0 SDK.
As for your question: there's a difference between compiling and running an application.
The NSXMLParserDelegate protocol was added in the iOS4 SDK. In previous versions of the SDK, the XML parser delegate methods were declared in a category. In iOS4, these methods have been moved to a dedicated protocol, which makes it a litte cleaner. At runtime, there's no difference. Once compiled, the app doesn't know anything about protocols or categories. The NSXMLParser will simply check if a specific delegate method is implemented (via respondsToSelctor), so it will run just fine.
In general, it's not a problem to build with iOS4 SDK and run on 3.0. You do have to make sure you don't call any methods that don't exist in 3.0. This is very easy to do by calling respondsToSelector. It allows you to create a single app that runs on all OS versions, but still allows you to call 4.0-specific methods.
I hope this makes sense ...

IPhone OS4 feature link error while run on OS3.x

I've compiled an app with IPhone base SDK 4.0, deployment target on iPhone OS 3.0. This app contains OS 4.0 new feature: local notification.
It works well on iPod 2G with OS 4.0; however it crashes every time the app start up on iPhone 1G with OS 3.0. It appears to be runtime reference error:
"dyld: Symbol not found: _OBJC_CLASS_$_UILocalNotification
Referenced from: /var/mobile/Applications/73A3FAB1-63AE-4A71-8C6B-932142A728FE/Tapatalk X.app/Tapatalk X
Expected in: /System/Library/Frameworks/UIKit.framework/UIKit"
If the UIKit framework is different between SDK3.0 & SDK4.0, why it doesn't report while compiling? How can I apply local notification feature on this app, while the app can still running on devices with OS3.0? Thanks.
This answer solved the problem for me:
That error is being triggered because
you didn't weak-link the UIKit
framework. The UIKit framework in
iPhone OS 3.2 added the
UISplitViewController, and if you link
it in as normal your application will
assume those symbols exist on 3.0,
where they don't.
To weak-link a framework, find your
application target in Xcode, inspect
it, and go to the General tab. At the
bottom of that tab should be a list of
frameworks, with a column for Type.
Change the Type for UIKit from
Required to Weak and rebuild your
application. That should take care of
the runtime errors.
This seems safe to me, given that UIKit is always going to be on the devices we're targetting.
If you use a 4.0 SDK feature and you want to support 3.0 devices, you need to check that the functionality exists before you use it.
If you're using a new class (as you are) something like the following should work:
Class localNotificationC = NSClassFromString(#"UILocalNotification");
if (localNotificationC) {
UILocalNotification* localNotification = [[localNotificationC alloc] init];
// do stuff
[localNotification release];
}
else {
// what to do with the 3.0 SDK
}
As for why the compiler doesn't tell you, well, you told the compiler that you were using the 4.0 SDK and those classes/methods work on 4.0.
I found this information really useful. However my question is how to test if the application crashes or not after this change.
The background is I had the same issue with my iPad application. I have my BaseSDK set as 4.3 and Deployment target is 3.2. I never got this crash while doing ad-hoc provisioning and running the app on 3.2 iPad and it got approved by Apple too. But users reported that when they started the application after download on iPad 3.2 it crashes before showing the main screen even.
I was using [UILocalNotifition alloc] in my code which I think could be the result of below crash:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x00000001, 0xe7ffdefe
I seem to have fixed this by converting the above statement as per Stephen's suggestion.
However I really don't know how to test it. I am not getting any crash earlier too while testing the application before submission on 3.2 and currently also I am not getting any crash on start up.
I really need to validate this fix before I push the update to app store. Could someone please shed more light on how to test this? It would be really helpful if I can reproduce this crash with the previous version of my application and the same is not the case with current version after this fix.