Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
8 changes: 5 additions & 3 deletions example/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -47,6 +48,7 @@ class logIn extends Component {
}
});
} else {
console.log(`Cached Access Token ${accessToken}`);
this.props.navigator.replace({
component: logInSuccess,
title: 'Success'
Expand Down
16 changes: 12 additions & 4 deletions example/ios/SpotifyAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"]]);
}

}];
Expand Down Expand Up @@ -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];
}
Expand Down