AFNetworking 2.0.3 not working on iOS 6 - iphone

I installed AFNetworking via CocoaPods:
pod "AFNetworking", '~> 2.0.3'
So, the method, which called from standart GET request:
- (NSURLSessionDataTask *)GET:(NSString *)URLString
parameters:(NSDictionary *)parameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
calls - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request; that returns nil on iOS 6.
Because AFNetworking uses NSURLSessionTask & NSURLSession which is introduced in iOS 7.0
And from AFNetworking Documentation:
New Requirements: iOS 6, Mac OS X 10.8, & Xcode 5
AFNetworking 2.0 officially supports iOS 6+, Mac OS X 10.8+, and Xcode 5.
Why it calls methods, that appears only in iOS7?

I found solution:
My API client inherit from AFHTTPSessionManager (like in afnetwoking site example).
But if you are using iOS 6 just leave inheritance from AFHTTPRequestOperationManager like in AFNetworking 1.x versions.
Replace:
#interface APIClient : AFHTTPSessionManager
to:
#interface APIClient : AFHTTPRequestOperationManager

Related

Build xCode project for xCode 3.2.5 and xCode 4.3.2 with NSUbiquitousKeyValueStore class

I've my iPhone project on the xCode 4.3.2 and it works well. It uses NSUbiquitousKeyValueStore class and it's base SDK is iOS 5.0.
Now I am going to build my project on the xCode 3.2.5 and it says error "Undefined symbol NSUbiquitousKeyValueStore".
Of course, I know NSUbiquitousKeyValueStore class is supported from iOS 5.0 and xCode 3.2.5 didn't supported iOS 5.0.
So I want to disable these features older the iOS 5.0, and enable over the iOS 5.0.
How can I do this?
Surround the code which makes use of features that were introduced with the 5.0 SDK like so:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
// Code using NSUbiquitousKeyValueStore goes here
#endif
Note that this is conditional compilation. The test is performed when building, not when running. So, if you build in an older version of Xcode without the 5.0 SDK, then the resulting program will never use NSUbiquitousKeyValueStore, no matter where you run it. There is no feasible way to build against an older SDK and yet still use feature of the newer SDK if they're available at runtime.
Edited to add: see Apple's SDK Compatibility Guide for more info.
You need to weak link the the framework that contain the NSUbiquitousKeyValueStore class.
Then in you code do something like things:
if ([NSUbiquitousKeyValueStore class]) {
// Class wil return non nil uf the class exists.
NSUbiquitousKeyValueStore *NSUbiquitousKeyValueStore = [NSUbiquitousKeyValueStore new];
}

dateByAddingTimeInterval method availability

I use dateByAddingTimeInterval method. I checked this method on iPhone with iOS 3.1 and it's worked! But in documentation said that this method available in iOS 4.0. Why this method worked in iOS 3.1?
It looks like an error in the documentation. The header specifies:
- (id)dateByAddingTimeInterval:(NSTimeInterval)ti NS_AVAILABLE(10_5, 2_0);
So it's available in 10.5, and iOS 2.0. That's why it is present in iOS 3 and later.

How to parse xml string in iphone 2.0

I am getting information (id,name,address) in the form of xml string form the .net web server.
i am using NSXMlparsing to parse this xml string in iphone os 4.0.
Now i need to do the same application in iphone os 2.0.
i found Nsxmlparsing delegate should work on 4.0 and later.
Can any one please suggest which method is suitable to parse xml string and sample tutorial.
Thank u in advance.
NSXMLParserDelegate was added in iOS 4.0.
You can declare that protocol with a #define directive to include the protocol declaration in iOS versions before 4.0 to be able to compile your code, but you don't necessarily have to include all methods in this protocol definition.
You can do something like this:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_4_0
#protocol NSXMLParserDelegate <NSObject>
#end
#endif
NSXMLParser has been available since iPhone OS 2.0. The delegate protocol has always been available as well, but prior to iOS 4.0 NSXMLParserDelegate was what is called an informal protocol, e.g. not explicitly defined.
As of iOS 4.0 many protocols that where previously informal has been promoted to actual format protocols, NSXMLParserDelegate is one of them.
The warning you get about not conforming to the protocol is building against SDK 4.0 and later, or missing protocol if building against an earlier SDK can be remedied by conforming to the protocol conditionally as such:
#interface MyClass : NSObject
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
<NSXMLParserDelegate>
#endif
{
// Your ivars here
}
// And methods here as usual
#end
Or you can make the compiler shut up by casting your delegate to id when setting it like this:
[myXMLParser setDelegate:(id)self]; // Assuming self is the delegate
Edited: NSXMLParser from doc
Availability Available in iOS 2.0 and later.
According to the NSXMLParser documentation, you can use it with iOS 2.0. The delegate documentation mentions iOS4. One of these is wrong, and I don't have an iOS 2.0 device to test this on, but have you tried your app in its current form? My assumption here is that the delegate documentation is wrong, and it does infact have support on 2.0.

If I use the NSXMLParserDelegate, will my application crash or be rejected if I target OS 3.1?

I am using the iPhone 4.0 SDK for my development and the NSXMLParserDelegate protocol in my code. I am planning to make this work on 3.1 as well by making the deployment target 3.1 and base SDK 4.0.
Since NSXMLParserDelegate is only on 4.0 and above will it work on iPhone 3.1?
Even if it works will Apple reject the app?
No, you can use APIs from later versions of the OS in builds for older versions, so long as you properly handle running on the older OS. This code is safe.

Can i use Base SDK 4.0 for iPad only app?

We are developing an iPad app for which I am trying to use sharekit http://getsharekit.com
I am getting this error if I use the Base SDK 3.2
Cannot find protocol declaration for NSXMLParserDelegate
But if I change Base SDK to 4.0 it works fine.
I think its possible to use Base SDK 4.0 when creating Universal apps.
Does anyone knows if apple accepts iPad only apps compiled with Base SDK as 4.0 and target 3.2?
It'll work. I'm using them in the same configuration currently, but I've been using NSXMLParserDelegate with 3.2 till too, not really sure why it won't work for you.
Was googling for NSXMLParserDelegate and came across this question -
Error Building Project With NSXMLParserDelegate
or
NSXMLParserDelegate compile problem - iPhone SDK 30. vs 4.0
Maybe this will work?