Skip to content

Commit

Permalink
Spotify iOS SDK v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jalopezcar committed May 10, 2024
1 parent c7757b8 commit 3f1e07a
Show file tree
Hide file tree
Showing 45 changed files with 186 additions and 59 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Spotify iOS SDK v2.0.1

What's New:
- Bumped the min deployment target version to iOS 12.0 in Package.swift

## Spotify iOS SDK v2.0.0

What's New:
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "SpotifyiOS",
platforms: [
.iOS(.v9)
.iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
150 changes: 136 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ Make sure you search existing issues before creating new ones.

### Requirements

The Spotify iOS framework requires a deployment target of iOS 9 or higher. The
following architectures are supported: `armv7`, `armv7s` and `arm64` for devices,
`i386` and `x86_64` for the iOS Simulator. Bitcode is also supported.
The Spotify iOS framework requires a deployment target of iOS 12 or higher.
The following architectures are supported in the SDK:

- device: arm64
- simulator: arm64 x86_64


## Components

Expand Down Expand Up @@ -146,13 +149,37 @@ Follow these steps to make sure you are prepared to start coding.
![Info.plist](img/info_plist.png)
3. Add `#import <SpotifyiOS/SpotifyiOS.h>` to your source files to import necessary headers.
3. Add the library to your source files.
*Swift*
```swift
import SpotifyiOS
```
*Objective-c*
```objective-c
#import <SpotifyiOS/SpotifyiOS.h>
```
### Check if Spotify is Active
If a user is already using Spotify, but has not authorized your application, you can use the following check to prompt them to
start the authorization process.
*Swift*
```swift
SPTAppRemote.checkIfSpotifyAppIsActive { active in
if active {
// Prompt the user to connect Spotify here
}
}
```

*Objective-c*

```objective-c
[SPTAppRemote checkIfSpotifyAppIsActive:^(BOOL active) {
if (active) {
Expand All @@ -167,19 +194,55 @@ To be able to use the playback control part of the SDK the user needs to authori
1. Initialize `SPTConfiguration` with your client ID and redirect URI.
*Swift*
```swift
let configuration = SPTConfiguration(
clientID: "YOUR_CLIENT_ID",
redirectURL: URL(string: "your_redirect_uri")!
)
```
*Objective-c*
```objective-c
SPTConfiguration *configuration =
[[SPTConfiguration alloc] initWithClientID:@"your_client_id" redirectURL:[NSURL URLWithString:@"your_redirect_uri"]];
SPTConfiguration *configuration = [[SPTConfiguration alloc] initWithClientID:@"your_client_id"
redirectURL:[NSURL URLWithString:@"your_redirect_uri"]];
```
2. Initialize `SPTAppRemote` with your `SPTConfiguration`
*Swift*
```swift
self.appRemote = SPTAppRemote(configuration: configuration, logLevel: .debug)
```
*Objective-c*
```objective-c
self.appRemote = [[SPTAppRemote alloc] initWithConfiguration:configuration logLevel:SPTAppRemoteLogLevelDebug];
```
3. Initiate the authentication flow (for other ways to detect if Spotify is installed, as well as attributing installs, please see our [Content Linking Guide](https://beta.developer.spotify.com/documentation/general/guides/content-linking-guide/)).
*Swift*
```swift
// Note: A blank string will play the user's last song or pick a random one.
self.appRemote.authorizeAndPlayURI("spotify:track:69bp2EbF7Q2rqc5N3ylezZ") { spotifyInstalled in
if !spotifyInstalled {
/*
* The Spotify app is not installed.
* Use SKStoreProductViewController with [SPTAppRemote spotifyItunesItemIdentifier] to present the user
* with a way to install the Spotify app.
*/
}
}
```
*Objective-c*
```objective-c
// Note: A blank string will play the user's last song or pick a random one.
[self.appRemote authorizeAndPlayURI:@"spotify:track:69bp2EbF7Q2rqc5N3ylezZ" completionHandler:^(BOOL spotifyInstalled) {
Expand All @@ -191,11 +254,13 @@ To be able to use the playback control part of the SDK the user needs to authori
*/
}
}];

```
4. Configure your `AppDelegate` to parse out the accessToken in `application:openURL:options:` and set it on the `SPTAppRemote` connectionParameters.
*Objective-c*
```objective-c
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
Expand All @@ -209,17 +274,19 @@ To be able to use the playback control part of the SDK the user needs to authori
return YES;
}
```

If you are using UIScene then you need to use appropriate method in your scene delegate.
*Swift*
```swift
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}

let parameters = appRemote.authorizationParameters(from: url);

if let access_token = parameters?[SPTAppRemoteAccessTokenKey] {
appRemote.connectionParameters.accessToken = access_token
self.accessToken = access_token
Expand All @@ -233,23 +300,45 @@ To be able to use the playback control part of the SDK the user needs to authori
1. Set your connection delegate and attempt to connect.
*Swift*
```Swift
self.appRemote.delegate = self
self.appRemote.connect()
```
```Swift
// MARK: AppRemoteDelegate
func appRemoteDidEstablishConnection(_ appRemote: SPTAppRemote) {
// Connection was successful, you can begin issuing commands
}
func appRemote(_ appRemote: SPTAppRemote, didFailConnectionAttemptWithError error: Error?) {
// Connection failed
}
func appRemote(_ appRemote: SPTAppRemote, didDisconnectWithError error: Error?) {
// Connection disconnected
}
```
*Objective-c*
```objective-c
self.appRemote.delegate = self;
[self.appRemote connect];
```

```objective-c

- (void)appRemoteDidEstablishConnection:(SPTAppRemote *)appRemote
{
// Connection was successful, you can begin issuing commands
}

- (void)appRemote:(SPTAppRemote *)appRemote didFailConnectionAttemptWithError:(NSError *)error
{
// Connection failed
}

- (void)appRemote:(SPTAppRemote *)appRemote didDisconnectWithError:(nullable NSError *)error
{
// Connection disconnected
Expand All @@ -258,6 +347,24 @@ To be able to use the playback control part of the SDK the user needs to authori
2. Set a delegate and subscribe to player state:
*Swift*
```Swift
self.appRemote.playerAPI?.delegate = self
appRemote.playerAPI?.subscribe(toPlayerState: { result, error in
// Handle Errors
})
```
```Swift
// MARK: SPTAppRemotePlayerStateDelegate
func playerStateDidChange(_ playerState: SPTAppRemotePlayerState) {
print("track name \(playerState.track.name)")
}
```
*Objective-c*
```objective-c
appRemote.playerAPI.delegate = self;
Expand All @@ -280,6 +387,19 @@ This tells Spotify that it's safe to disable the active stream. If your app does
If you want your app to automatically reconnect after disruption events like incoming calls or Siri interactions you may use the `willResignActive` and `didBecomeActive` callbacks to safely disconnect and reconnect. If you don't wish to reconnect directly, it's typically enough to close the connection in `didEnterBackground` callbacks.
*Swift*
```swift
func sceneWillResignActive(_ scene: UIScene) {
self.appRemote.disconnect()
}
func sceneDidBecomeActive(_ scene: UIScene) {
self.appRemote.connect()
}
```

*Objective-c*

```objective-c
- (void)applicationWillResignActive:(UIApplication *)application
{
Expand All @@ -289,7 +409,9 @@ If you want your app to automatically reconnect after disruption events like inc
{
[self.appRemote connect];
}

// If you're using UIWindowSceneDelegate

- (void)sceneDidBecomeActive:(UIScene *)scene
{
[self.appRemote connect];
Expand Down
10 changes: 5 additions & 5 deletions SpotifyiOS.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>SpotifyiOS.framework/SpotifyiOS</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>SpotifyiOS.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>SpotifyiOS.framework/SpotifyiOS</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>SpotifyiOS.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file modified SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/SpotifyiOS
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/html/Blocks/SPTAppRemoteCallback.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTAppRemote.html
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTAppRemoteConnectionParams.html
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTConfiguration.html
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTError.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h2 class="subtitle subtitle-overview">Overview</h2>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTSession.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Classes/SPTSessionManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/Constants/SPTAppRemoteErrorCode.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ <h4 class="method-subtitle">Declared In</h4>
<footer>
<div class="footer-copyright">

<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-08</p>
<p class="copyright">Copyright &copy; 2024 Spotify. All rights reserved. Updated: 2024-05-10</p>


<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
Expand Down
Loading

0 comments on commit 3f1e07a

Please sign in to comment.