Permalink
Browse files

Revert to previous APIs for initialising SPSession.

Init methods with block callbacks make me sad :-(

Change-Id: I4fdd08bdffc4e343c30057a540e779483feb4d21
  • Loading branch information...
1 parent fade67b commit bd2a7d030950e5488f19c449c68e791e01b6b0a0 @iKenndac iKenndac committed Nov 14, 2012
@@ -50,17 +50,18 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *userAgent = [[[NSBundle mainBundle] infoDictionary] valueForKey:(__bridge NSString *)kCFBundleIdentifierKey];
NSData *appKey = [NSData dataWithBytes:&g_appkey length:g_appkey_size];
- [SPSession createSharedSessionWithKey:appKey
- userAgent:userAgent
- loadingPolicy:SPAsyncLoadingManual
- callback:^(SPSession *sharedSession, NSError *error) {
- if (error != nil) {
- NSLog(@"[%@ %@]: FATAL: Failed to initialise SPSession with error: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), error);
- abort();
- }
-
- [[SPSession sharedSession] setDelegate:self];
- }];
+ NSError *error = nil;
+ [SPSession initializeSharedSessionWithApplicationKey:appKey
+ userAgent:userAgent
+ loadingPolicy:SPAsyncLoadingManual
+ error:&error];
+ if (error != nil) {
+ NSLog(@"CocoaLibSpotify init failed: %@", error);
+ abort();
+ }
+
+ [[SPSession sharedSession] setDelegate:self];
+
}
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
@@ -80,14 +80,19 @@ @implementation Guess_The_IntroAppDelegate
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
- [SPSession createSharedSessionWithKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
- userAgent:@"com.spotify.GuessTheIntro"
- loadingPolicy:SPAsyncLoadingImmediate
- callback:^(SPSession *sharedSession, NSError *error) {
- [[SPSession sharedSession] setDelegate:self];
- self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
- self.playbackManager.delegate = self;
- }];
+ NSError *error = nil;
+ [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
+ userAgent:@"com.spotify.GuessTheIntro"
+ loadingPolicy:SPAsyncLoadingImmediate
+ error:&error];
+ if (error != nil) {
+ NSLog(@"CocoaLibSpotify init failed: %@", error);
+ abort();
+ }
+
+ [[SPSession sharedSession] setDelegate:self];
+ self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
+ self.playbackManager.delegate = self;
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], @"CreatePlaylist",
@@ -45,13 +45,19 @@ @implementation AppDelegate
-(void)applicationWillFinishLaunching:(NSNotification *)notification {
[self willChangeValueForKey:@"session"];
- [SPSession createSharedSessionWithKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
- userAgent:@"com.spotify.OfflinePlaylists"
- loadingPolicy:SPAsyncLoadingImmediate
- callback:^(SPSession *sharedSession, NSError *error) {
- [[SPSession sharedSession] setDelegate:self];
- self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
- }];
+ NSError *error = nil;
+ [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
+ userAgent:@"com.spotify.OfflinePlaylists"
+ loadingPolicy:SPAsyncLoadingImmediate
+ error:&error];
+ if (error != nil) {
+ NSLog(@"CocoaLibSpotify init failed: %@", error);
+ abort();
+ }
+
+ [[SPSession sharedSession] setDelegate:self];
+ self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
+
[self didChangeValueForKey:@"session"];
[self.window center];
[self.window orderFront:nil];
@@ -46,13 +46,19 @@ @implementation SimplePlayerAppDelegate
-(void)applicationWillFinishLaunching:(NSNotification *)notification {
- [SPSession createSharedSessionWithKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
- userAgent:@"com.spotify.SimplePlayer"
- loadingPolicy:SPAsyncLoadingManual
- callback:^(SPSession *sharedSession, NSError *error) {
- [[SPSession sharedSession] setDelegate:self];
- self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
- }];
+ NSError *error = nil;
+ [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
+ userAgent:@"com.spotify.SimplePlayer"
+ loadingPolicy:SPAsyncLoadingManual
+ error:&error];
+ if (error != nil) {
+ NSLog(@"CocoaLibSpotify init failed: %@", error);
+ abort();
+ }
+
+ [[SPSession sharedSession] setDelegate:self];
+ self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
+
[self.window center];
[self.window orderFront:nil];
}
View
@@ -124,37 +124,15 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
store your SPSession object using this convenience method or yourself using -[SPSession init],
make sure you only have _one_ instance of SPSession active in your process at a time.
- @warning This will return `nil` until +[SPSession createSharedSessionWithKey:userAgent:loadingPolicy:callback:] is
+ @warning This will return `nil` until +[SPSession initializeSharedSessionWithApplicationKey:userAgent:loadingPolicy:error:] is
successfully called.
*/
+(SPSession *)sharedSession;
-/** Creates the shared SPSession object.
-
- Your application key and user agent must be valid to create an SPSession object.
-
- @warning The C API that CocoaLibSpotify uses (LibSpotify) doesn't
- support using multiple sessions in the same process. While you can either create and
- store your SPSession object using this convenience method or yourself using -[SPSession initWithKey:userAgent:loadingPolicy:callback:],
- make sure you only have _one_ instance of SPSession active in your process at a time.
-
- @param appKey Your application key as an NSData.
- @param userAgent Your application's user agent (for example, com.yourcompany.MyGreatApp).
- @param policy The loading policy to use.
- @param block The block to be invoked when the session is created (or not).
- @return The shared `SPSession` object, which won't be useable until the `block` callback is fired.
- */
-+(SPSession *)createSharedSessionWithKey:(NSData *)appKey
- userAgent:(NSString *)userAgent
- loadingPolicy:(SPAsyncLoadingPolicy)policy
- callback:(void (^)(SPSession *sharedSession, NSError *error))block;
-
-/** DEPRECATED: Initializes the shared SPSession object.
+/** Initializes the shared SPSession object.
Your application key and user agent must be valid to create an SPSession object.
- @warning This method has been deprecated. Use -[SPSession createSharedSessionWithKey:userAgent:loadingPolicy:callback:] instead.
-
@warning The C API that CocoaLibSpotify uses (LibSpotify) doesn't
support using multiple sessions in the same process. While you can either create and
store your SPSession object using this convenience method or yourself using +[SPSession initWithApplicationKey:userAgent:loadingPolicy:error:],
@@ -169,8 +147,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+(BOOL)initializeSharedSessionWithApplicationKey:(NSData *)appKey
userAgent:(NSString *)userAgent
loadingPolicy:(SPAsyncLoadingPolicy)policy
- error:(NSError **)error
-__attribute__((deprecated("Use +createSharedSessionWithKey:userAgent:loadingPolicy:callback: instead")));
+ error:(NSError **)error;
/** The "debug" build ID of libspotify.
@@ -188,23 +165,6 @@ __attribute__((deprecated("Use +createSharedSessionWithKey:userAgent:loadingPoli
/** Initialize a new SPSession object.
Your application key and user agent must be valid to create an SPSession object. This is SPSession's designated initializer.
-
-@param appKey Your application key as an NSData.
-@param userAgent Your application's user agent (for example, com.yourcompany.MyGreatApp).
-@param policy The loading policy to use.
-@param block The block to be invoked when the session is ready for use (or not).
-@return Returns a newly initialised SPSession object.
- */
--(id)initWithKey:(NSData *)appKey
- userAgent:(NSString *)userAgent
- loadingPolicy:(SPAsyncLoadingPolicy)policy
- callback:(void (^)(SPSession *session, NSError *error))block;
-
-/** DEPRECATED: Initialize a new SPSession object.
-
- @warning This method has been deprecated. Use -[SPSession initWithKey:userAgent:loadingPolicy:callback:] instead.
-
- Your application key and user agent must be valid to create an SPSession object. This is SPSession's designated initializer.
@param appKey Your application key as an NSData.
@param userAgent Your application's user agent (for example, com.yourcompany.MyGreatApp).
@@ -215,8 +175,7 @@ __attribute__((deprecated("Use +createSharedSessionWithKey:userAgent:loadingPoli
-(id)initWithApplicationKey:(NSData *)appKey
userAgent:(NSString *)userAgent
loadingPolicy:(SPAsyncLoadingPolicy)policy
- error:(NSError **)error
-__attribute__((deprecated("Use -initWithKey:userAgent:loadingPolicy:callback: instead")));
+ error:(NSError **)error;
/** Attempt to login to the Spotify service.
Oops, something went wrong.

0 comments on commit bd2a7d0

Please sign in to comment.