Permalink
Browse files

example project

  • Loading branch information...
1 parent 2eca700 commit f5de9ec41773a4a272a98bc43d9f63dd68ff52fa @greenisus committed May 28, 2010
Showing with 9,955 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +28 −0 Example/ASIAuthenticationDialog.h
  3. +236 −0 Example/ASIAuthenticationDialog.m
  4. +76 −0 Example/ASIFormDataRequest.h
  5. +358 −0 Example/ASIFormDataRequest.m
  6. +769 −0 Example/ASIHTTPRequest.h
  7. +3,764 −0 Example/ASIHTTPRequest.m
  8. +55 −0 Example/ASIHTTPRequestConfig.h
  9. +33 −0 Example/ASIHTTPRequestDelegate.h
  10. +26 −0 Example/ASIInputStream.h
  11. +136 −0 Example/ASIInputStream.m
  12. +16 −0 Example/ASINSStringAdditions.h
  13. +28 −0 Example/ASINSStringAdditions.m
  14. +110 −0 Example/ASINetworkQueue.h
  15. +339 −0 Example/ASINetworkQueue.m
  16. +38 −0 Example/ASIProgressDelegate.h
  17. +25 −0 Example/AtomParser.h
  18. +105 −0 Example/AtomParser.m
  19. +36 −0 Example/Classes/DetailViewController.h
  20. +295 −0 Example/Classes/DetailViewController.m
  21. +31 −0 Example/Classes/ExampleAppDelegate.h
  22. +52 −0 Example/Classes/ExampleAppDelegate.m
  23. +19 −0 Example/Classes/RootViewController.h
  24. +161 −0 Example/Classes/RootViewController.m
  25. +498 −0 Example/DetailView.xib
  26. +37 −0 Example/Example-Info.plist
  27. +382 −0 Example/Example.xcodeproj/project.pbxproj
  28. +14 −0 Example/Example_Prefix.pch
  29. +33 −0 Example/FeedItem.h
  30. +30 −0 Example/FeedItem.m
  31. +570 −0 Example/FeedItemCell.xib
  32. +579 −0 Example/MainWindow.xib
  33. 0 Example/README
  34. +554 −0 Example/RSSEmptyCell.xib
  35. +25 −0 Example/RSSParser.h
  36. +115 −0 Example/RSSParser.m
  37. +88 −0 Example/Reachability.h
  38. +274 −0 Example/Reachability.m
  39. +17 −0 Example/main.m
  40. BIN Example/rssgrey337.png
View
@@ -0,0 +1,3 @@
+Example/build
+Example/Example.xcodeproj/mike.pbxuser
+Example/Example.xcodeproj/mike.mode1v3
@@ -0,0 +1,28 @@
+//
+// ASIAuthenticationDialog.h
+// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
+//
+// Created by Ben Copsey on 21/08/2009.
+// Copyright 2009 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class ASIHTTPRequest;
+
+typedef enum _ASIAuthenticationType {
+ ASIStandardAuthenticationType = 0,
+ ASIProxyAuthenticationType = 1
+} ASIAuthenticationType;
+
+@interface ASIAuthenticationDialog : NSObject <UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource> {
+ ASIHTTPRequest *request;
+ UIActionSheet *loginDialog;
+ ASIAuthenticationType type;
+}
++ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
++ (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
+
+@property (retain) ASIHTTPRequest *request;
+@property (retain) UIActionSheet *loginDialog;
+@property (assign) ASIAuthenticationType type;
+@end
@@ -0,0 +1,236 @@
+//
+// ASIAuthenticationDialog.m
+// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
+//
+// Created by Ben Copsey on 21/08/2009.
+// Copyright 2009 All-Seeing Interactive. All rights reserved.
+//
+
+#import "ASIAuthenticationDialog.h"
+#import "ASIHTTPRequest.h"
+
+ASIAuthenticationDialog *sharedDialog = nil;
+NSLock *dialogLock = nil;
+
+@interface ASIAuthenticationDialog ()
+- (void)show;
+@end
+
+@implementation ASIAuthenticationDialog
+
++ (void)initialize
+{
+ if (self == [ASIAuthenticationDialog class]) {
+ dialogLock = [[NSLock alloc] init];
+ }
+}
+
++ (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request
+{
+ [dialogLock lock];
+ [sharedDialog release];
+ sharedDialog = [[self alloc] init];
+ [sharedDialog setRequest:request];
+ [sharedDialog setType:ASIProxyAuthenticationType];
+ [sharedDialog show];
+ [dialogLock unlock];
+}
+
++ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request
+{
+ [dialogLock lock];
+ [sharedDialog release];
+ sharedDialog = [[self alloc] init];
+ [sharedDialog setRequest:request];
+ [sharedDialog show];
+ [dialogLock unlock];
+
+}
+
+- (void)show
+{
+ // Create an action sheet to show the login dialog
+ [self setLoginDialog:[[[UIActionSheet alloc] init] autorelease]];
+ [[self loginDialog] setActionSheetStyle:UIActionSheetStyleBlackOpaque];
+ [[self loginDialog] setDelegate:self];
+
+ // We show the login form in a table view, similar to Safari's authentication dialog
+ UITableView *table = [[[UITableView alloc] initWithFrame:CGRectMake(0,80,320,480) style:UITableViewStyleGrouped] autorelease];
+ [table setDelegate:self];
+ [table setDataSource:self];
+ [[self loginDialog] addSubview:table];
+ [[self loginDialog] showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]];
+ [[self loginDialog] setFrame:CGRectMake(0,0,320,480)];
+
+ // Setup the title (Couldn't figure out how to put this in the same toolbar as the buttons)
+ UIToolbar *titleBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,30)] autorelease];
+ UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10,0,300,30)] autorelease];
+ if ([self type] == ASIProxyAuthenticationType) {
+ [label setText:@"Login to this secure proxy server."];
+ } else {
+ [label setText:@"Login to this secure server."];
+ }
+ [label setTextColor:[UIColor blackColor]];
+ [label setFont:[UIFont systemFontOfSize:13.0]];
+ [label setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
+ [label setShadowOffset:CGSizeMake(0, 1.0)];
+ [label setOpaque:NO];
+ [label setBackgroundColor:nil];
+ [label setTextAlignment:UITextAlignmentCenter];
+
+ [titleBar addSubview:label];
+ [[self loginDialog] addSubview:titleBar];
+
+ // Setup the toolbar
+ UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,30,320,50)] autorelease];
+
+ NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
+ UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease];
+ [items addObject:backButton];
+
+ label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,170,50)] autorelease];
+ if ([self type] == ASIProxyAuthenticationType) {
+ [label setText:[[self request] proxyHost]];
+ } else {
+ [label setText:[[[self request] url] host]];
+ }
+ [label setTextColor:[UIColor whiteColor]];
+ [label setFont:[UIFont boldSystemFontOfSize:22.0]];
+ [label setShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
+ [label setShadowOffset:CGSizeMake(0, -1.0)];
+ [label setOpaque:NO];
+ [label setBackgroundColor:nil];
+ [label setTextAlignment:UITextAlignmentCenter];
+
+ [toolbar addSubview:label];
+
+ UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil] autorelease];
+ [labelButton setCustomView:label];
+ [items addObject:labelButton];
+ [items addObject:[[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)] autorelease]];
+ [toolbar setItems:items];
+
+ [[self loginDialog] addSubview:toolbar];
+
+ // Force reload the table content, and focus the first field to show the keyboard
+ [table reloadData];
+ [[[[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] subviews] objectAtIndex:2] becomeFirstResponder];
+
+}
+
+- (void)cancelAuthenticationFromDialog:(id)sender
+{
+ [[self request] cancelAuthentication];
+ [[self loginDialog] dismissWithClickedButtonIndex:0 animated:YES];
+}
+
+- (void)loginWithCredentialsFromDialog:(id)sender
+{
+ NSString *username = [[[[[[[self loginDialog] subviews] objectAtIndex:0] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] subviews] objectAtIndex:2] text];
+ NSString *password = [[[[[[[self loginDialog] subviews] objectAtIndex:0] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]] subviews] objectAtIndex:2] text];
+
+ if ([self type] == ASIProxyAuthenticationType) {
+ [[self request] setProxyUsername:username];
+ [[self request] setProxyPassword:password];
+ } else {
+ [[self request] setUsername:username];
+ [[self request] setPassword:password];
+ }
+
+ // Handle NTLM domains
+ NSString *scheme = ([self type] == ASIStandardAuthenticationType) ? [[self request] authenticationScheme] : [[self request] proxyAuthenticationScheme];
+ if ([scheme isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeNTLM]) {
+ NSString *domain = [[[[[[[self loginDialog] subviews] objectAtIndex:0] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]] subviews] objectAtIndex:2] text];
+ if ([self type] == ASIProxyAuthenticationType) {
+ [[self request] setProxyDomain:domain];
+ } else {
+ [[self request] setDomain:domain];
+ }
+ }
+
+ [[self loginDialog] dismissWithClickedButtonIndex:1 animated:YES];
+ [[self request] retryUsingSuppliedCredentials];
+}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ NSString *scheme = ([self type] == ASIStandardAuthenticationType) ? [[self request] authenticationScheme] : [[self request] proxyAuthenticationScheme];
+ if ([scheme isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeNTLM]) {
+ return 3;
+ }
+ return 2;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
+{
+ if (section == [self numberOfSectionsInTableView:tableView]-1) {
+ return 30;
+ }
+ return 0;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
+{
+ if (section == 0) {
+ return 30;
+ }
+ return 0;
+}
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+ if (section == 0) {
+ return [[self request] authenticationRealm];
+ }
+ return nil;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_0
+ UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
+#else
+ UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
+#endif
+
+ [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
+ UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(20,12,260,25)] autorelease];
+ [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ if ([indexPath section] == 0) {
+ [textField setPlaceholder:@"User"];
+ } else if ([indexPath section] == 1) {
+ [textField setPlaceholder:@"Password"];
+ [textField setSecureTextEntry:YES];
+ } else if ([indexPath section] == 2) {
+ [textField setPlaceholder:@"Domain"];
+ }
+ [cell addSubview:textField];
+
+ return cell;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return 1;
+}
+
+
+- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
+{
+ if (section == [self numberOfSectionsInTableView:tableView]-1) {
+ // If we're using Basic authentication and the connection is not using SSL, we'll show the plain text message
+ if ([[[self request] authenticationScheme] isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeBasic] && ![[[[self request] url] scheme] isEqualToString:@"https"]) {
+ return @"Password will be sent in the clear.";
+ // We are using Digest, NTLM, or any scheme over SSL
+ } else {
+ return @"Password will be sent securely.";
+ }
+ }
+ return nil;
+}
+
+@synthesize request;
+@synthesize loginDialog;
+@synthesize type;
+@end
@@ -0,0 +1,76 @@
+//
+// ASIFormDataRequest.h
+// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
+//
+// Created by Ben Copsey on 07/11/2008.
+// Copyright 2008-2009 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "ASIHTTPRequest.h"
+#import "ASIHTTPRequestConfig.h"
+
+typedef enum _ASIPostFormat {
+ ASIMultipartFormDataPostFormat = 0,
+ ASIURLEncodedPostFormat = 1
+
+} ASIPostFormat;
+
+@interface ASIFormDataRequest : ASIHTTPRequest <NSCopying> {
+
+ // Parameters that will be POSTed to the url
+ NSMutableArray *postData;
+
+ // Files that will be POSTed to the url
+ NSMutableArray *fileData;
+
+ ASIPostFormat postFormat;
+
+ NSStringEncoding stringEncoding;
+
+#if DEBUG_FORM_DATA_REQUEST
+ // Will store a string version of the request body that will be printed to the console when ASIHTTPREQUEST_DEBUG is set in GCC_PREPROCESSOR_DEFINITIONS
+ NSString *debugBodyString;
+#endif
+
+}
+
+#pragma mark utilities
+- (NSString*)encodeURL:(NSString *)string;
+
+#pragma mark setup request
+
+// Add a POST variable to the request
+- (void)addPostValue:(id <NSObject>)value forKey:(NSString *)key;
+
+// Set a POST variable for this request, clearing any others with the same key
+- (void)setPostValue:(id <NSObject>)value forKey:(NSString *)key;
+
+// Add the contents of a local file to the request
+- (void)addFile:(NSString *)filePath forKey:(NSString *)key;
+
+// Same as above, but you can specify the content-type and file name
+- (void)addFile:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key;
+
+// Add the contents of a local file to the request, clearing any others with the same key
+- (void)setFile:(NSString *)filePath forKey:(NSString *)key;
+
+// Same as above, but you can specify the content-type and file name
+- (void)setFile:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key;
+
+// Add the contents of an NSData object to the request
+- (void)addData:(NSData *)data forKey:(NSString *)key;
+
+// Same as above, but you can specify the content-type and file name
+- (void)addData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key;
+
+// Add the contents of an NSData object to the request, clearing any others with the same key
+- (void)setData:(NSData *)data forKey:(NSString *)key;
+
+// Same as above, but you can specify the content-type and file name
+- (void)setData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key;
+
+
+@property (assign) ASIPostFormat postFormat;
+@property (assign) NSStringEncoding stringEncoding;
+@end
Oops, something went wrong.

0 comments on commit f5de9ec

Please sign in to comment.