Ben Copsey

Use nanotech's rotation code for ASIAuthenticationDialog instead - it's animated…

…, and seems to be more reliable on iOS3 device
Fix deprecated warning in ASIDownloadCache
Tweaks to sample iphone app - rotation fixes, remove bandwidth use bar for now
... ... @@ -8,7 +8,7 @@
#import "ASIAuthenticationDialog.h"
#import "ASIHTTPRequest.h"
#import <CoreGraphics/CoreGraphics.h>
#import <QuartzCore/QuartzCore.h>
static ASIAuthenticationDialog *sharedDialog = nil;
BOOL isDismissing = NO;
... ... @@ -127,33 +127,46 @@ static const NSUInteger kDomainSection = 1;
// Manually handles orientation changes on iPhone
- (void)orientationChanged:(NSNotification *)notification
{
[[self view] setTransform:CGAffineTransformIdentity];
[self showTitle];
CGRect frame = [[self view] frame];
[[self view] setCenter:CGPointMake(frame.size.height/2,frame.size.width/2)];
float targetRotation = 0;
frame = [[UIScreen mainScreen] bounds];
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationPortraitUpsideDown:
targetRotation = 180;
frame = CGRectMake(0, 0, frame.size.width, frame.size.height-20);
break;
case UIDeviceOrientationLandscapeLeft:
targetRotation = 90;
frame = CGRectMake(0, 0, frame.size.width-20, frame.size.height);
break;
case UIDeviceOrientationLandscapeRight:
frame = CGRectMake(20, 0, frame.size.width-20, frame.size.height);
targetRotation = 270;
break;
case UIDeviceOrientationPortrait:
frame = CGRectMake(0, 20, frame.size.width, frame.size.height-20);
break;
UIDeviceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat angle = 0;
switch (o) {
case UIDeviceOrientationLandscapeLeft: angle = 90; break;
case UIDeviceOrientationLandscapeRight: angle = -90; break;
case UIDeviceOrientationPortraitUpsideDown: angle = 180; break;
default: break;
}
[[self view] setTransform:CGAffineTransformMakeRotation(targetRotation / 180.0 * M_PI)];
[[self view] setFrame:frame];
CGRect f = [[UIScreen mainScreen] applicationFrame];
// Swap the frame height and width if necessary
if (UIDeviceOrientationIsLandscape(o)) {
CGFloat t;
t = f.size.width;
f.size.width = f.size.height;
f.size.height = t;
}
CGAffineTransform previousTransform = self.view.layer.affineTransform;
CGAffineTransform newTransform = CGAffineTransformMakeRotation(angle * M_PI / 180.0);
// Reset the transform so we can set the size
self.view.layer.affineTransform = CGAffineTransformIdentity;
self.view.frame = (CGRect){0,0,f.size};
// Revert to the previous transform for correct animation
self.view.layer.affineTransform = previousTransform;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
// Set the new transform
self.view.layer.affineTransform = newTransform;
// Fix the view origin
self.view.frame = (CGRect){f.origin.x,f.origin.y,self.view.frame.size};
[UIView commitAnimations];
}
#pragma mark utilities
... ... @@ -165,7 +178,7 @@ static const NSUInteger kDomainSection = 1;
// Attach to the window, but don't interfere.
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
[window addSubview:presentingController.view];
[window addSubview:[presentingController view]];
[[presentingController view] setFrame:CGRectZero];
[[presentingController view] setUserInteractionEnabled:NO];
}
... ...
... ... @@ -61,7 +61,7 @@ static NSString *permanentCacheFolder = @"PermanentStore";
[[self accessLock] unlock];
[NSException raise:@"FileExistsAtCachePath" format:@"Cannot create a directory for the cache at '%@', because a file already exists",directory];
} else if (!exists) {
[[NSFileManager defaultManager] createDirectoryAtPath:directory attributes:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:NO attributes:nil error:nil];
if (![[NSFileManager defaultManager] fileExistsAtPath:directory]) {
[[self accessLock] unlock];
[NSException raise:@"FailedToCreateCacheDirectory" format:@"Failed to create a directory for the cache at '%@'",directory];
... ... @@ -296,10 +296,10 @@ static NSString *permanentCacheFolder = @"PermanentStore";
return;
}
NSString *path;
if (storagePolicy == ASICacheForSessionDurationCacheStoragePolicy) {
path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder];
} else if (storagePolicy == ASICachePermanentlyCacheStoragePolicy) {
if (storagePolicy == ASICachePermanentlyCacheStoragePolicy) {
path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder];
} else {
path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder];
}
BOOL isDirectory = NO;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory];
... ...
... ... @@ -24,7 +24,7 @@
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.7-9 2010-06-30";
NSString *ASIHTTPRequestVersion = @"v1.7-10 2010-07-02";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ...
... ... @@ -111,6 +111,8 @@
[responseField setBackgroundColor:[UIColor clearColor]];
[responseField setEditable:NO];
[responseField setText:@"Secret information will appear here if authentication succeeds"];
[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
}
static NSString *intro = @"Demonstrates fetching content from an area that requires HTTP authentication. You will be prompted for a username and password, enter 'topsecret' for both.\nIf you turn on keychain support, successful authentication will result in the username and password you provided being stored in your keychain. The application will use these details rather than prompt you the next time.\nToggle 'Use built-in dialog' to switch between ASIHTTPRequest's built-in dialog, and one created by the delegate.";
... ...
... ... @@ -94,6 +94,7 @@
- (void)viewDidLoad
{
[[[self navigationBar] topItem] setTitle:@"Using a Queue"];
[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
}
static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASINetworkQueue to track progress.\r\nEach request has its own downloadProgressDelegate, and the queue has an additional downloadProgressDelegate to track overall progress.";
... ...
... ... @@ -13,7 +13,7 @@
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="2"/>
<integer value="106"/>
<integer value="126"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
... ... @@ -46,18 +46,6 @@
<int key="NSvFlags">1316</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIToolbar" id="565443135">
<reference key="NSNextResponder" ref="380026005"/>
<int key="NSvFlags">1290</int>
<string key="NSFrame">{{0, -1}, {320, 44}}</string>
<reference key="NSSuperview" ref="380026005"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableArray" key="IBUIItems">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<object class="IBUILabel" id="633748759">
<reference key="NSNextResponder" ref="380026005"/>
<int key="NSvFlags">1316</int>
... ... @@ -207,15 +195,7 @@
<reference key="source" ref="664661524"/>
<reference key="destination" ref="1034742383"/>
</object>
<int key="connectionID">113</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">statusMessage</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="633748759"/>
</object>
<int key="connectionID">129</int>
<int key="connectionID">147</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
... ... @@ -232,7 +212,6 @@
<reference key="object" ref="380026005"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="565443135"/>
<reference ref="633748759"/>
</object>
<reference key="parent" ref="0"/>
... ... @@ -332,11 +311,6 @@
<reference key="object" ref="633748759"/>
<reference key="parent" ref="380026005"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">130</int>
<reference key="object" ref="565443135"/>
<reference key="parent" ref="380026005"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
... ... @@ -357,7 +331,6 @@
<string>124.CustomClassName</string>
<string>126.CustomClassName</string>
<string>128.IBPluginDependency</string>
<string>130.IBPluginDependency</string>
<string>2.IBAttributePlaceholdersKey</string>
<string>2.IBEditorWindowLastContentRect</string>
<string>2.IBPluginDependency</string>
... ... @@ -368,7 +341,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIApplication</string>
<string>UIResponder</string>
<string>{{474, 471}, {320, 480}}</string>
<string>{{654, 389}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>SynchronousViewController</string>
... ... @@ -380,7 +353,6 @@
<string>UploadViewController</string>
<string>AuthenticationViewController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSMutableDictionary">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
... ... @@ -410,7 +382,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">131</int>
<int key="maxID">147</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
... ... @@ -497,7 +469,7 @@
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">SampleViewController.h</string>
<string key="minorKey">iPhone Sample/SampleViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
... ... @@ -577,13 +549,11 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>statusMessage</string>
<string>tabBarController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UILabel</string>
<string>UITabBarController</string>
<string>UIWindow</string>
</object>
... ... @@ -592,17 +562,12 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>statusMessage</string>
<string>tabBarController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">statusMessage</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">tabBarController</string>
<string key="candidateClassName">UITabBarController</string>
</object>
... ...
... ... @@ -41,6 +41,7 @@ Most of the code below here relates to the table view, and isn't that interestin
- (void)viewDidLoad
{
[[[self navigationBar] topItem] setTitle:@"Synchronous Requests"];
[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
... ...
... ... @@ -74,6 +74,8 @@
resultView = [[UITextView alloc] initWithFrame:CGRectZero];
[resultView setBackgroundColor:[UIColor clearColor]];
progressIndicator = [[UIProgressView alloc] initWithFrame:CGRectZero];
[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
}
static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload progress.\nYou'll only see accurate progress for uploads when the request body is larger than 128KB (in 2.2.1 SDK), or when the request body is larger than 32KB (in 3.0 SDK)";
... ...
... ... @@ -9,13 +9,10 @@
#import <UIKit/UIKit.h>
@interface iPhoneSampleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
IBOutlet UILabel *statusMessage;
IBOutlet UIWindow *window;
IBOutlet UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) UIWindow *window;
@end
... ...
... ... @@ -7,44 +7,22 @@
//
#import "iPhoneSampleAppDelegate.h"
#import "ASIHTTPRequest.h"
#import "Reachability.h"
@implementation iPhoneSampleAppDelegate
- (void)dealloc
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[tabBarController release];
[window release];
[super dealloc];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
[window addSubview:[tabBarController view]];
[[tabBarController view] setFrame:CGRectMake(0,42,320,438)];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateStatus:) userInfo:nil repeats:YES];
[[tabBarController view] setFrame:CGRectMake(0, 0, 320, 480)];
[window addSubview:[tabBarController view]];
}
// This is really just so I can test reachability + throttling is working. Please don't use a timer to do this in your own apps!
- (void)updateStatus:(NSTimer *)timer
- (void)dealloc
{
NSString *connectionType;
if ([ASIHTTPRequest isNetworkReachableViaWWAN]) {
connectionType = @"Using WWAN";
} else {
connectionType = @"Not using WWAN";
}
NSString *throttling = @"Throttling OFF";
if ([ASIHTTPRequest isBandwidthThrottled]) {
throttling = @"Throttling ON";
}
[statusMessage setText:[NSString stringWithFormat:@"%@ / %luKB per second / %@",connectionType, [ASIHTTPRequest averageBandwidthUsedPerSecond]/1024,throttling]];
[window release];
[super dealloc];
}
@synthesize window;
@synthesize tabBarController;
@end
... ...
This diff was suppressed by a .gitattributes entry.