From 9d16eba6f033eb4f81f065a206e0499118848374 Mon Sep 17 00:00:00 2001 From: aahan96 Date: Tue, 30 Jan 2018 16:27:11 -0600 Subject: [PATCH 1/4] Fix for issue #19 --- example/index.ios.js | 10 ++++++---- example/ios/SpotifyAuth.m | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/example/index.ios.js b/example/index.ios.js index 5ab8206..b9e329e 100644 --- a/example/index.ios.js +++ b/example/index.ios.js @@ -16,7 +16,7 @@ const SpotifyModule = NativeModules.SpotifyModule; class logIn extends Component { componentWillMount() { - return SpotifyModule.initWithCredentials('YOUR_CLIENT_ID','YOUR_REDIRECT_URL',['streaming'],(error) => { + return SpotifyModule.initWithCredentials('448dfcfaec7a4bb1a1d30f8874bd78f1','sample://callback',['streaming'],(error) => { if(error){ alert(`some ${error}`); } @@ -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..e6dddb4 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. @@ -615,9 +620,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 +692,12 @@ -(void)urlCallback: (NSURL *)url { } else { if (session) { + NSLog(@"here we go"); + NSString *tempStr = session.accessToken; + NSLog(@"Message == %@",tempStr); + NSLog(@"and we go"); + loginRes[@"token"] = tempStr; + [center postNotificationName:@"loginRes" object:nil userInfo:loginRes]; // login to the player [self.player loginWithAccessToken:self.auth.session.accessToken]; } From ea6f8f467a59bd172a3a9a9f37656b4b4e6d9755 Mon Sep 17 00:00:00 2001 From: aahan96 Date: Tue, 30 Jan 2018 16:30:42 -0600 Subject: [PATCH 2/4] Fix for #19 --- example/index.ios.js | 2 +- example/ios/SpotifyAuth.m | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/example/index.ios.js b/example/index.ios.js index b9e329e..d0fde94 100644 --- a/example/index.ios.js +++ b/example/index.ios.js @@ -16,7 +16,7 @@ const SpotifyModule = NativeModules.SpotifyModule; class logIn extends Component { componentWillMount() { - return SpotifyModule.initWithCredentials('448dfcfaec7a4bb1a1d30f8874bd78f1','sample://callback',['streaming'],(error) => { + return SpotifyModule.initWithCredentials('your-credentials','your-callback',['streaming'],(error) => { if(error){ alert(`some ${error}`); } diff --git a/example/ios/SpotifyAuth.m b/example/ios/SpotifyAuth.m index e6dddb4..212237b 100644 --- a/example/ios/SpotifyAuth.m +++ b/example/ios/SpotifyAuth.m @@ -483,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. From 36d0d1c5749ac85b0d07d7bbd2bb64f12d9b0755 Mon Sep 17 00:00:00 2001 From: Aahan Sawhney <96aahan@gmail.com> Date: Tue, 30 Jan 2018 16:38:36 -0600 Subject: [PATCH 3/4] Update index.ios.js Fixed naming for credentials --- example/index.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/index.ios.js b/example/index.ios.js index d0fde94..605ddda 100644 --- a/example/index.ios.js +++ b/example/index.ios.js @@ -16,7 +16,7 @@ const SpotifyModule = NativeModules.SpotifyModule; class logIn extends Component { componentWillMount() { - return SpotifyModule.initWithCredentials('your-credentials','your-callback',['streaming'],(error) => { + return SpotifyModule.initWithCredentials('YOUR_CLIENT_ID','YOUR_REDIRECT_URL',['streaming'],(error) => { if(error){ alert(`some ${error}`); } From c4683369c5eef0b26d5d7761df1acc6c995077c7 Mon Sep 17 00:00:00 2001 From: Aahan Sawhney <96aahan@gmail.com> Date: Tue, 30 Jan 2018 16:40:37 -0600 Subject: [PATCH 4/4] Update SpotifyAuth.m Removed junky code --- example/ios/SpotifyAuth.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/example/ios/SpotifyAuth.m b/example/ios/SpotifyAuth.m index 212237b..d2156f1 100644 --- a/example/ios/SpotifyAuth.m +++ b/example/ios/SpotifyAuth.m @@ -693,11 +693,7 @@ -(void)urlCallback: (NSURL *)url { } else { if (session) { - NSLog(@"here we go"); - NSString *tempStr = session.accessToken; - NSLog(@"Message == %@",tempStr); - NSLog(@"and we go"); - loginRes[@"token"] = tempStr; + loginRes[@"token"] = session.accessToken; [center postNotificationName:@"loginRes" object:nil userInfo:loginRes]; // login to the player [self.player loginWithAccessToken:self.auth.session.accessToken];