Skip to content

Commit

Permalink
Use conditional compliation for choosing a progress delegate API
Browse files Browse the repository at this point in the history
Hopefully this will prevent App Store rejections based on the use of setMaxValue:
  • Loading branch information
pokeb committed Nov 17, 2009
1 parent 430dfb5 commit d4e036d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
24 changes: 12 additions & 12 deletions Classes/ASIHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ - (void)setUploadProgressDelegate:(id)newDelegate
[[self cancelledLock] lock];

uploadProgressDelegate = newDelegate;


#if !TARGET_OS_IPHONE
// If the uploadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
SEL selector = @selector(setMaxValue:);
if ([uploadProgressDelegate respondsToSelector:selector]) {
Expand All @@ -1010,6 +1011,7 @@ - (void)setUploadProgressDelegate:(id)newDelegate
[invocation invoke];

}
#endif
[[self cancelledLock] unlock];
}

Expand All @@ -1018,7 +1020,8 @@ - (void)setDownloadProgressDelegate:(id)newDelegate
[[self cancelledLock] lock];

downloadProgressDelegate = newDelegate;


#if !TARGET_OS_IPHONE
// If the downloadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
SEL selector = @selector(setMaxValue:);
if ([downloadProgressDelegate respondsToSelector:selector]) {
Expand All @@ -1029,6 +1032,7 @@ - (void)setDownloadProgressDelegate:(id)newDelegate
[invocation setArgument:&max atIndex:2];
[invocation invokeWithTarget:downloadProgressDelegate];
}
#endif
[[self cancelledLock] unlock];
}

Expand Down Expand Up @@ -1142,7 +1146,6 @@ - (void)resetDownloadProgress:(unsigned long long)value
- (void)updateDownloadProgress
{


// We won't update download progress until we've examined the headers, since we might need to authenticate
if ([self responseHeaders] && ([self contentLength] || [self complete])) {

Expand Down Expand Up @@ -1220,7 +1223,8 @@ + (void)setProgress:(double)progress forProgressIndicator:(id)indicator

SEL selector;
[progressLock lock];


#if TARGET_OS_IPHONE
// Cocoa Touch: UIProgressView
if ([indicator respondsToSelector:@selector(setProgress:)]) {
selector = @selector(setProgress:);
Expand All @@ -1229,23 +1233,19 @@ + (void)setProgress:(double)progress forProgressIndicator:(id)indicator
[invocation setSelector:selector];
float progressFloat = (float)progress; // UIProgressView wants a float for the progress parameter
[invocation setArgument:&progressFloat atIndex:2];

// If we're running in the main thread, update the progress straight away. Otherwise, it's not that urgent
[invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:indicator waitUntilDone:[NSThread isMainThread]];

}
#else
// Cocoa: NSProgressIndicator
} else if ([indicator respondsToSelector:@selector(setDoubleValue:)]) {
if ([indicator respondsToSelector:@selector(setDoubleValue:)]) {
selector = @selector(setDoubleValue:);
NSMethodSignature *signature = [[indicator class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
[invocation setArgument:&progress atIndex:2];


[invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:indicator waitUntilDone:[NSThread isMainThread]];

}
#endif
[progressLock unlock];
}

Expand Down
12 changes: 8 additions & 4 deletions Classes/ASINetworkQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ - (void)cancelAllOperations
- (void)setUploadProgressDelegate:(id)newDelegate
{
uploadProgressDelegate = newDelegate;


#if !TARGET_OS_IPHONE
// If the uploadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
SEL selector = @selector(setMaxValue:);
if ([[self uploadProgressDelegate] respondsToSelector:selector]) {
Expand All @@ -97,14 +98,16 @@ - (void)setUploadProgressDelegate:(id)newDelegate
[invocation setSelector:selector];
[invocation setArgument:&max atIndex:2];
[invocation invokeWithTarget:[self uploadProgressDelegate]];
}
}
#endif
}


- (void)setDownloadProgressDelegate:(id)newDelegate
{
downloadProgressDelegate = newDelegate;


#if !TARGET_OS_IPHONE
// If the downloadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
SEL selector = @selector(setMaxValue:);
if ([[self downloadProgressDelegate] respondsToSelector:selector]) {
Expand All @@ -114,7 +117,8 @@ - (void)setDownloadProgressDelegate:(id)newDelegate
[invocation setSelector:@selector(setMaxValue:)];
[invocation setArgument:&max atIndex:2];
[invocation invokeWithTarget:[self downloadProgressDelegate]];
}
}
#endif
}

- (void)addHEADOperation:(NSOperation *)operation
Expand Down

0 comments on commit d4e036d

Please sign in to comment.