HTTP with username password authentication and XML parsing iPhone - iphone

I want to download data from HTTP using username and password for authentication using objective-c. And want to download the data which will be returned. And want to parse it for usage, like if the data gets downloaded successfully a new screen will be opened and if data could not be downloaded it would take me to another screen.
Please let me know if there is any full tutorial related to this or let me know how can I do this .. ?
thanks in advance

You should definitely check out Apple's SeismicXML code, it is really simple to follow and uses classes native to apple. In this example, an RSS feed is downloaded and displayed by parsing the XML. I am using this modified code to query Amazon and download product information. Check it out here:
http://developer.apple.com/library/ios/#samplecode/SeismicXML/Listings/ReadMe_txt.html
I hope this helps!

Use the connection delegate
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// To get into a new view controller. Push the newviewcontroller with the help of navigation controller.
}
and use the parsing delegate
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
//To use the parsing data to be displayed in other view controller.Push the Otherviewcontroller with the help of navigation controller.
}

Related

image gallery from server in ios

I'm working on retreiving images from server and display it in ios.I select the image that I need to see on full screen it comes. But the problem is, once I go back, it reloads the whole images again from server. Are there any solution so as to save it in cache file for a while. I searched the whole internet for this, but didn't get a proper solution. Can any one please specify best tutorial for that. I'm newbie to ios
If each time you go back it reloads all the images agin from the server is probably because you may either create a new view or because you are calling to load the images from the method viewWillAppear instead of in the viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Load the images here...
}
Instead of in here:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
If this doesn't not help, please provide us with some code.

FBConnect's handleOpenURL Method Not Called by my AppDelegate

I have implemented the FBConnect SDK into my app, and it works perfectly on the simulator. I then modified my app's .plist file appropriately, and added the necessary method to my AppDelegate for when Facebook is installed on the device:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"handleOpenURL Method was called and sent the following:");
NSString *urlString = [NSString stringWithContentsOfURL:(NSURL *)url];
NSLog(#"URL String: %#", urlString);
return [[flipsideViewController facebook] handleOpenURL:url];
}
From the above NSLogs and the observation that my application is returned to the foreground after authorizing access via Facebook, I infer that the FB App is handing off control to my application appropriately. Unfortunately, Facebook.m's "handleOpenURL:url" method does not actually get called as I request in my AppDelegate (i.e. neither of the below NSLogs are displayed).
- (BOOL)handleOpenURL:(NSURL *)url {
// If the URL's structure doesn't match the structure used for Facebook authorization, abort.
NSLog(#"handleOpenURL was handled by SDK. Good!");
if (![[url absoluteString] hasPrefix:[self getOwnBaseUrl]]) {
NSLog(#"handleOpenURL structure doesn't match the structure used for Facebook authorization. Aborting.");
return NO;
}
//...
As a result, my app's view controller (where I clicked my facebook button to begin with) is simply returned to the screen, and the code I placed in the 'fbDidLogin' method (used in my view controller to publish to the user's wall) never gets called as it did in the simulator.
What am I overlooking? What, if any, other information is needed to solve this problem? Any help would be very much appreciated, as I have been struggling with this for a while.
Important Summary Notes:
1.) Application runs as desired on simulator.
2.) handleOpenURL Method not called when I request it from my AppDelegate.
3.) I do not receive any errors/warnings.
4.) I can run the DemoApp on my device, and I notice that the handleOpenURL Method is called appropiately when requested by the 'DemoAppAppDelegate.'
Thanks in Advance!
I ended up having to make my facebook object a singleton (stored in the appDelegate). Not completely sure why this was necessary though, as I was not using the fb object in multiple viewControllers. Please comment if you know why this was necessary.
See the following links for more information:
handleOpenUrl and TabBar Application
Facebook SDK: Call from multiple viewControllers
Cocoa with Love: Singletons

Video capture on an iPhone; captureOutput delegate never called

Hey folks. Trying to get started with iPhone video capture stuff, and having a terrible time getting it going.
At the moment, working with an exact copy of the sample code from this Apple Developer Q&A: qa1702; not going to re-paste it here, since it's a relatively big blob of code.
In any case, I copied and pasted that code into an otherwise-empty project, threw in a call to setupCaptureSession into a custom UIView, and figured I should be good to go:
- (void)awakeFromNib {
NSLog(#"init");
[self setupCaptureSession];
}
Unfortunately, when I run the code, my delegate never seems to be called:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
NSLog(#"New Image!");
}
I'd expect to be seeing a flood of "New Image!" getting dumped to the log, but I'm getting absolutely nothing. I do know that all the initialization code is being run (I threw a few NSLog statements here and there within setupCaptureSession, and they all print).
So, I'd either A) like to figure out what I'm doing wrong or B) see some very simple capture code embedded into a UIView that actually works (the less code, the better). Ideally, the sample code would use the setupCaptureSession code as described in the Apple developer site above.
Note that this code is being tested on an iPhone 3GS running the newest version of iOS 4.
Thanks in advance!
I copied and pasted the same code into a new project and it works fine for me.
Here is what I did:
I created a View Based application in XCode.
I added the following frameworks:CoreMedia, CoreVideo,AVFoundation
I imported AVFoundation into my viewcontroller's header file
I specified my view controller to use the AVCaptureVideoDataOutputSampleBufferDelegate protocol in its interface definition
In the implementation I copied the code from the app document you specified in your question
I commented out this:
[self setSession:session]
I commented out this:
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
and added this:
NSLog(#"here");
In the viewDidLoad method i put
[self setupCaptureSession];
Build. Run.
The "here" gets printed repeatedly to the console.

UIWebView loading progress and adjust web page to fit the view page?

I am using UIWebView to load a web page.
There are 3 questions:
1.It it possible to track the percentage progress when UIWebView is loading the page?
2.I noticed that when Safari loading a web page, the URL textfield displays a blue background progress indicator to tell user the percentage of loading a web page. What is the technology for this?
3.I know there is property scalesPageToFit
scalesPageToFit
A Boolean value determining whether the webpage scales to fit the view and the user can change the scale.
I try to set it to YES, but it looks like that it is not in public API and my app stopped with black screen, I am not sure what is wrong?
To answer #1)
Instead of using a UIWebView, you can pull the webpage down as an NSData object using an NSURLConnection. When you get the initial response from your request from
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
the webserver should return a value of "expected content size" (which should be included in the response). Then you will keep getting the following method called each time you receive data:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
Keep appending the data to an existing NSMutableData object. Then you can check the size of your current data object (NSMutableData.length) against the expected response size.
percentage = (myData.length*100)/theResponse.expectedContentSize;
Then you can update a progress bar with that percentage! When
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
runs, use your data to call
[myWebView loadData:myData MIMEType:myMimeType textEncodingName:myEncoding baseURL:baseURL];
and it will load everything you pulled down into your web view.
Re #3:
You can try specifying scalePagesToFit as a YES in the viewDidLoad event of the UIView that contains your webview, e.g:
- (void)viewDidLoad {
self.webView.scalesPageToFit = YES;
//other code here...
}
For cases where this doesn't work, refer to the following StackOverflow question: UIWebView does not scale content to fit where the asker (and subsequently, answerer) gave this solution.
Apparently you can use javascript to resize your page to fit the browser:
NSString *jsCommand = [NSString stringWithFormat:#"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];
You can try to use this subclass of UIWebView which uses private UIWebView methods - therefore, this solution is not 100% AppStore safe (though some apps do almost 100% use it: Facebook, Google app, ...).
https://github.com/petr-inmite/imtwebview
Re #2: I believe Safari uses a private API call on UITextField (so you can't do it if you want to submit to the app store), but you should be able to implement this yourself by putting a textfield with no border over the top of a progress bar.
To answer question #1, there is a solution that is App Store safe, and uses a similar method as Webkit to track progress.
https://github.com/otium/OTMWebView

iPhone: How to Determine When a Download from a URL has Completed

I need to populate an array using data from a NSURL. How do I determine when the download from the URL has completed?
You usually use NSURLConnection and then set its delegate to whatever object controls the download. When NSURLConnection finishes it sends connectionDidFinishLoading: to the delegate to signal completion.
See the URL System Programming Guide.
there is delegate method will be called when all the data from url is download.- (void)connectionDidFinishLoading:(NSURLConnection *)connection {}