How to parse xml string in iphone 2.0 - iphone

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.

Related

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 do you make an iOS 4.0 app compatible with iPhone OS 3.1.3?

So, I may have made a mistake in updating my application to iOS 4.0 by wiping my Xcode installation and only installing the 4.0 SDK (I can't even find SDK 3.1.3 in my backups, doh!). I have an app now that has been built with a base SDK of 4.0 and it says in iTunes it requires 4.0 but the only thing I added was the methods -applicationDidEnterBackgroundState and -applicationDidBecomeActive (basically just copied and pasted the save/load data code from -applicationWillTerminate and -viewDidLoad). Is it possible that I can rebuild the app with the iPhone OS Deployment Target set to 3.1.3 in the Build Settings and Apple will allow me to essentially downgrade my app? Should I put in those #If_Define statements that check for 4.0 so it will conditionally enable those 4.0 methods?
No, you shouldn't need to use #ifdef statements. You can call a method anything you want - the question is whether or not the UIApplication instance will call it :).
Also, your deployment settings will handle the iTunes issue, I believe. So, you should set it to 3.1.3 (or 3.0 unless specifically required, a lot of people I know didn't upgrade between the 3s because there were minimal features and many times it was essentially an anti-jailbreak release).
As for the code, I've handled this issue like this:
- (void) applicationWillTerminate:(UIApplication *)application
{
// Just pass it on to the new iOS4 delegate
NSLog(#"Application will terminate");
[self applicationDidEnterBackground:application];
}
And for the foreground, I just have a "loader" method that is called both from application:didFinishLaunchingWithOptions: and applicationWillEnterForeground:.
Works well for my software on my 3G w/ 3.0 (I refuse to upgrade after seeing iOS4 on a 3G!) as well as my 3GS running iOS4.

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?

MPMediaPickerControllerDelegate error

I get an error when trying to use MPMediaPickerControllerDelegate even though I have added the reference to the framework and added
#import <MediaPlayer/MediaPlayer.h>
The error I get is:
"error: cannot find protocol declaration for 'MPMediaPickerControllerDelegate'"
I'm trying to have a single binary work for iPhone OS 2.2 and 3.0, so I set the Base SDK to 3.0 and iPhone OS deployment target to iPhone OS 2.2
What could I be doing wrong?
Whats wrong here is that MPMediaPickerControllerDelegate is not available in any version of the OS before 3.0, so you wont be able to run that on the OS 2.2 and if you dont find a way around using this class it wont be compatible with OS 2.2, from reading the docs it looks like this class is f or IPod access on the iphone, thats a 3.0 only feature...

Can I use iPhone 3.0 symbols when building for 2.2.1?

I've been working on iPhone app for awhile and still want to support 2.2.1
One of the features is that the user can start the app via email by clicking a link. In the 2.2.1 world, I accomplished this by implemting the application: handleOpenURL: message.
In iPhone 3.0, they've changed things up adding the application: didFinishLaunchingWithOptions: method (which is great, and makes a lot more sense than the old way). In that method, you use the key UIApplicationLaunchOptionsURLKey to find out what the URL was.
The problem is, if I use that key my app doesn't build in 2.2.1 since it was introduced in 3.0. What's the most elegant way to get around this and still support 2.2.1? I was thinking of using the actual value for the UIApplicationLaunchOptionsURLKey enum, but I figured that was ugly. Has anybody encountered this and think of a better way?
The simplest way is to #define around the 3.0 code and 2.2.1 code so you can do conditional compilation. Note: This means you will have one binary for 3.0 and another for the other.
so
#ifdef IPHONE_OS_3.0
/* DO 3.0 stuff */
#endif
#ifdef IPHONE_OS_2.2.1
/*DO 2.2.1 stuff */
#endif
In response to your comment, you would have to have a different #ifdef #endif for each code block if the code is going to be different, otherwise if it is only different for 3.0 you would do something like
#ifdef IPHONE_OS_3.0
/* DO 3.0 STUFF */
#else
/* DO STUFF FOR OTHER THAN 3.0 */
#endif
You are going to have to figure out what the real definitions are (I just made them up :))
Hope that helps
Use the 3.0 SDK, but set the "iPhone OS Deployment Target" to 2.2.1 or earlier.
Under OS 3.0, your application: didFinishLaunchingWithOptions: will get called, and if you're running on OS 2.2.1, one of the old methods will get called.
If you're not trying to use any other 3.0 features, I don't think you'll need to do anything else, but you could also look at my other answer about Apple's MailComposer sample.
To have a single app that works on both OS versions, you have to build against the 2.2.1 SDK. And since that SDK has no idea the UIApplicationLaunchOptionsURLKey symbol, you have no choice but to define it in your code if you recognise it value when your app is run on OS 3.0.
On the other hand, adoption of OS 3.0 is very strong (upwards of 75% already, according to one figure I've seen), so making your app OS 3.0 only is also a solution to consider.
There's a question about 3.0 features in 2.0 iPhone OS. But you want to know (at run time) if a symbol exits in the UIKit or whereever. I'm afraid, that's not answered there, yet.
So what should you too if you want to have a single binary that supports multiple OS versions? I'm especially stuck on how to conditionally load the necessary libraries for 3.0.
#ifdef __IPHONE_3_0
// iPhone 3.0 specific stuff
#else
// iPhone 2.2 (or below) specific stuff
#endif