Skip to content

Commit 260a3fd

Browse files
committed
Fix #97: Better error handling on spotify not installed
- Use method from ios sdk to check if spotify is installed - update for better error message - cleanup commented code
1 parent 5cdf417 commit 260a3fd

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

ios/RNSpotifyRemoteAppRemote.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ - (void)appRemote:(nonnull SPTAppRemote *)appRemote didDisconnectWithError:(null
150150
}
151151

152152
- (void)appRemote:(nonnull SPTAppRemote *)appRemote didFailConnectionAttemptWithError:(nullable NSError *)error {
153-
// Check if spotify is installed
154-
if(![RCTSharedApplication() canOpenURL:[NSURL URLWithString:@"spotify://https://open.spotify.com/track/2FhN2KhUvT91Q3Er4v9Qpd?si=6TZmH5MTRpqozJmvRUD_4Q"]] ){
155-
[RNSpotifyRemotePromise rejectCompletions:_appRemoteCallbacks error:[RNSpotifyRemoteError errorWithCodeObj:RNSpotifyRemoteErrorCode.SpotifyNotInstalled ]];
156-
}else{
153+
// Check if spotify is installed
154+
if(![RNSpotifyRemoteAuth.sharedInstance isSpotifyInstalled]){
155+
[RNSpotifyRemotePromise rejectCompletions:_appRemoteCallbacks error:[RNSpotifyRemoteError errorWithCodeObj:RNSpotifyRemoteErrorCode.SpotifyNotInstalled ]];
156+
}else{
157157
[RNSpotifyRemotePromise rejectCompletions:_appRemoteCallbacks error:[RNSpotifyRemoteError errorWithNSError:error]];
158-
};
158+
};
159159
}
160160

161161
- (void)appRemoteDidEstablishConnection:(nonnull SPTAppRemote *)connectedRemote {

ios/RNSpotifyRemoteAuth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-(void)authorize:(NSDictionary*)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
1717
-(void)endSession:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
1818
-(void)getSession:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
19-
19+
-(BOOL)isSpotifyInstalled;
2020

2121
-(SPTConfiguration*) configuration;
2222
-(NSString*) accessToken;

ios/RNSpotifyRemoteAuth.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ -(id)init
7171
return sharedInstance;
7272
}
7373

74+
-(BOOL)isSpotifyInstalled{
75+
return _sessionManager != nil && _sessionManager.spotifyAppInstalled;
76+
}
77+
7478
#pragma mark URL handling
7579

7680
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)URL options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options

ios/RNSpotifyRemoteConvert.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22
#import <Foundation/Foundation.h>
3-
//#import <SpotifyAuthentication/SpotifyAuthentication.h>
4-
//#import <SpotifyMetadata/SpotifyMetadata.h>
5-
//#import <SpotifyAudioPlayback/SpotifyAudioPlayback.h>
63
#import <SpotifyiOS.h>
74
#import "RNSpotifyRemoteError.h"
85

ios/RNSpotifyRemoteError.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ +(RNSpotifyRemoteErrorCode*)errorName { \
3939
DEFINE_SPOTIFY_ERROR_CODE(SessionClosed, @"Session has been closed")
4040
DEFINE_SPOTIFY_ERROR_CODE(AppRemoteDisconnected, @"App Remote is not connected")
4141
DEFINE_SPOTIFY_ERROR_CODE(UnknownResponse, @"Spotify returned an unknown response")
42-
DEFINE_SPOTIFY_ERROR_CODE(SpotifyNotInstalled, @"Spotify does not appear to be installed")
42+
DEFINE_SPOTIFY_ERROR_CODE(SpotifyNotInstalled, @"Spotify does not appear to be installed. Note: You must whitelist the 'spotify' URL scheme in your info.plist.")
4343

4444
#undef DEFINE_SPOTIFY_ERROR_CODE
4545

0 commit comments

Comments
 (0)