diff --git a/README.md b/README.md index 071cc05..08132b7 100644 --- a/README.md +++ b/README.md @@ -131,13 +131,13 @@ Returns true when SPTAudioStreamingController is initialized, otherwise false Example: -`SpotifyModule.initialized((res)=>{console.log(res);});` +`SpotifyModule.initialized((res, accessToken)=>{console.log(res, accessToken);});` --- **[loggedIn](https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTAudioStreamingController.html#//api/name/loggedIn)** -Returns true if the receiver is logged into the Spotify service, otherwise false +Returns a boolean if the receiver is logged into the Spotify service or not, and also returns the Spotify access token if you also want to use the web API. | Parameter |description| diff --git a/example/index.ios.js b/example/index.ios.js index 5ab8206..12c2be3 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..e9b98fe 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"], @"Error finding user token"]); + } 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]; }