Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use respondsToSelector for optional protocol methods

  • Loading branch information...
commit 53e99d0230a60369c11a607c35a4698f136ac3a3 1 parent b35870a
Chris Lucas authored May 01, 2012
4  Classes/AudioStreamer.h
@@ -108,7 +108,7 @@ typedef enum
108 108
 extern NSString * const ASStatusChangedNotification;
109 109
 extern NSString * const ASPresentAlertWithTitleNotification;
110 110
 
111  
-@protocol AudioStreamerDelegate
  111
+@protocol AudioStreamerDelegate <NSObject>
112 112
 @optional
113 113
 //
114 114
 // this method does not work with seeking
@@ -207,7 +207,7 @@ extern NSString * const ASPresentAlertWithTitleNotification;
207 207
 @property (readwrite) BOOL debug;
208 208
 @property (readwrite) int bytesDownloaded;
209 209
 @property (readwrite) int bytesExpected; // is set to -1 if seekToTime is called as it's unreliable
210  
-@property (retain, nonatomic) id <AudioStreamerDelegate> delegate;
  210
+@property (assign, nonatomic) id <AudioStreamerDelegate> delegate;
211 211
 
212 212
 - (id)initWithURL:(NSURL *)aURL;
213 213
 //- (id)initWithURL:(NSURL *)aURL encryption:(EncryptionMethod)method crc32:(uLong)crc32;
7  Classes/AudioStreamer.m
@@ -1522,7 +1522,8 @@ - (void)handleReadFromStream:(CFReadStreamRef)aStream
1522 1522
         //
1523 1523
         // send message audioStreamDidFinishDownloading:withBytesDownloaded: to delegate
1524 1524
         //
1525  
-        if (self.bytesDownloaded == self.bytesExpected) {
  1525
+        if ([self.delegate respondsToSelector:@selector(audioStreamDidFinishDownloading:withBytesDownloaded:)] && 
  1526
+            (self.bytesDownloaded == self.bytesExpected)) {
1526 1527
             [self.delegate audioStreamDidFinishDownloading:self withBytesDownloaded:self.bytesDownloaded];
1527 1528
         }
1528 1529
 	}
@@ -2231,7 +2232,9 @@ - (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
2231 2232
 			if (state == AS_STOPPING)
2232 2233
 			{
2233 2234
 				self.state = AS_STOPPED;
2234  
-                [self.delegate audioStreamDidFinishPlaying:self];
  2235
+                if ([self.delegate respondsToSelector:@selector(audioStreamDidFinishPlaying:)]) {
  2236
+                    [self.delegate audioStreamDidFinishPlaying:self];
  2237
+                }
2235 2238
 			}
2236 2239
 			else if (state == AS_WAITING_FOR_QUEUE_TO_START)
2237 2240
 			{
5  Classes/iPhoneStreamingPlayerViewController.m
@@ -389,6 +389,11 @@ -(void)audioStreamDidFinishDownloading:(id)sender
389 389
     NSLog(@"delegate test, numBytes = %d", numBytes); 
390 390
 }
391 391
 
  392
+-(void)audioStreamDidFinishPlaying:(id)sender
  393
+{
  394
+    NSLog(@"audioStreamDidFinishPlaying delegation received");
  395
+}
  396
+
392 397
 #pragma mark Remote Control Events
393 398
 /* The iPod controls will send these events when the app is in the background */
394 399
 - (void)remoteControlReceivedWithEvent:(UIEvent *)event {
13  iPhoneStreamingPlayer.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
3 3
 	archiveVersion = 1;
4 4
 	classes = {
5 5
 	};
6  
-	objectVersion = 45;
  6
+	objectVersion = 46;
7 7
 	objects = {
8 8
 
9 9
 /* Begin PBXBuildFile section */
@@ -190,8 +190,11 @@
190 190
 /* Begin PBXProject section */
191 191
 		29B97313FDCFA39411CA2CEA /* Project object */ = {
192 192
 			isa = PBXProject;
  193
+			attributes = {
  194
+				LastUpgradeCheck = 0420;
  195
+			};
193 196
 			buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "iPhoneStreamingPlayer" */;
194  
-			compatibilityVersion = "Xcode 3.1";
  197
+			compatibilityVersion = "Xcode 3.2";
195 198
 			developmentRegion = English;
196 199
 			hasScannedForEncodings = 1;
197 200
 			knownRegions = (
@@ -282,9 +285,8 @@
282 285
 				GCC_WARN_UNUSED_VARIABLE = YES;
283 286
 				IPHONEOS_DEPLOYMENT_TARGET = 3.0;
284 287
 				ONLY_ACTIVE_ARCH = YES;
285  
-				PREBINDING = NO;
286 288
 				PROVISIONING_PROFILE = "";
287  
-				SDKROOT = iphoneos4.1;
  289
+				SDKROOT = iphoneos;
288 290
 			};
289 291
 			name = Debug;
290 292
 		};
@@ -298,10 +300,9 @@
298 300
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
299 301
 				GCC_WARN_UNUSED_VARIABLE = YES;
300 302
 				IPHONEOS_DEPLOYMENT_TARGET = 2.0;
301  
-				PREBINDING = NO;
302 303
 				PROVISIONING_PROFILE = "86DAA109-AB22-49C8-94E7-3D80E70FAAB5";
303 304
 				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "86DAA109-AB22-49C8-94E7-3D80E70FAAB5";
304  
-				SDKROOT = iphoneos4.1;
  305
+				SDKROOT = iphoneos;
305 306
 			};
306 307
 			name = Release;
307 308
 		};

0 notes on commit 53e99d0

Please sign in to comment.
Something went wrong with that request. Please try again.