diff --git a/example/index.ios.js b/example/index.ios.js index 5ab8206..605ddda 100644 --- a/example/index.ios.js +++ b/example/index.ios.js @@ -33,11 +33,12 @@ class logIn extends Component { style={styles.button} onPress={() => { //Start Auth process - SpotifyModule.loggedIn((res) => { + SpotifyModule.loggedIn((res, accessToken) => { console.warn(res) if(!res) { - SpotifyModule.startAuthenticationFlow((error) => { - if(!error){ + SpotifyModule.startAuthenticationFlow((error, str) => { + if(!error){ + console.log("New Access Token = "+str); this.props.navigator.replace({ component: logInSuccess, title: 'Success' @@ -47,6 +48,7 @@ class logIn extends Component { } }); } else { + console.log("Cached Access Token = "+accessToken); this.props.navigator.replace({ component: logInSuccess, title: 'Success' diff --git a/example/ios/SpotifyAuth.m b/example/ios/SpotifyAuth.m index a746971..d2156f1 100644 --- a/example/ios/SpotifyAuth.m +++ b/example/ios/SpotifyAuth.m @@ -83,7 +83,12 @@ @implementation SpotifyAuth RCT_EXPORT_METHOD(loggedIn:(RCTResponseSenderBlock)block) { SPTAudioStreamingController *sharedIn = [SPTAudioStreamingController sharedInstance]; - block(@[@([sharedIn loggedIn])]); + if([sharedIn loggedIn]) { + block(@[@([sharedIn loggedIn]), self.auth.session.accessToken]); + + } else { + block(@[@([sharedIn loggedIn])]); + } } //Returns the volume, as a value between 0.0 and 1.0. @@ -478,6 +483,7 @@ - (void)audioStreaming:(SPTAudioStreamingController *)audioStreaming didStartPla - (void)audioStreaming:(SPTAudioStreamingController *)audioStreaming didStopPlayingTrack:(NSString *)trackUri { [self sendEventWithName:@"didStopPlayingTrack" body:@{@"trackUri": trackUri}]; + } /** Called when the audio streaming object requests playback skips to the next track. @@ -615,9 +621,9 @@ - (void)audioStreamingDidPopQueue:(SPTAudioStreamingController *)audioStreaming { //if there is an error key in the userInfo dictionary send the error, otherwise null if(notification.userInfo[@"error"] != nil){ - block(@[notification.userInfo[@"error"]]); - } else { - block(@[[NSNull null]]); + block(@[notification.userInfo[@"error"], @"not wow"]); + } else if(notification.userInfo[@"token"] != nil) { + block(@[[NSNull null], notification.userInfo[@"token"]]); } }]; @@ -687,6 +693,8 @@ -(void)urlCallback: (NSURL *)url { } else { if (session) { + loginRes[@"token"] = session.accessToken; + [center postNotificationName:@"loginRes" object:nil userInfo:loginRes]; // login to the player [self.player loginWithAccessToken:self.auth.session.accessToken]; }