iOS Spotify SDK - Swift 5 Tutorial
One of the subjects that I think plays a big role in our lives is music. That’s why I wanted to do a little application research about spotify. I decided that the resources were not very sufficient and I wanted to
prepare a tutorial by myself. So Let’s start !?????
1 - Create A New XCode Project
We will have to use the name of the application, so you can choose a name that you can work with more easily.
2 - Login to spotify developer website Here.
Then click on the dashboard from the menu at the top, you will see the create a app button on the page that comes up, after clicking on it, we need to enter our app name on the page that opens,?but this name should be the same as the xcode file we created.
That’s all for now, we’ll be back here later !
3 - Install Spotify SDK from Here.
At the same time, let’s install the Spotify SDK file from the package dependencies section.
Then add ObjC Flag. Since many SDK is written in objective c library we have to do this and apply it in our swift file.
Then we need to add Objective-C File to our App.
You can give the name you want, then we will delete it.
This will then ask you if you want Xcode to create a bridging file for your. Say yes Create Bridging Header.
Then delete the objective c file and only the bridging header file remains and add?#import <SpotifyiOS/ SpotifyiOS.h>?this code snippet.
4 - Setting up the info.plist
We can say that this process is the most important point required to use this SDK.
We need to set these settings in our developer app :
Bundle ID and Redirect URI
In p.list we need to set them :
URL Types, Queried URL Schemes and App Transport Security Settings.
领英推荐
5 - Let’s Configure Our App
Click the edit settings button in our spotify developer dashboard. Write your application name in the redirect uri and add?“ :// ”. In the bundle id part, we copy and paste the bundle id in our xcode file.
In the end it should look like this.
After saving our settings, we move on to configuring our application in Xcode.
6 - Setting up Xcode
We open the demo application in the downloaded file.
We should copy and paste the parts I said into our own Xcode file. Which is?URL Types, Queried URL Schemes and App Transport Security Settings.
After copy paste, our application should look like this. Our application name in Item 0 part. In the identifier part, it will be enough to enter the bundle id.
7- Building App
You can also check out Spotify’s own auth guide?here.?Our application will need a refresh token in order to provide transactions, in this we need to get permission from our application first.
Let’s create a swift file named Constants and add this code init:
We need to add our own keys to the places in the code. You can find it in dashboard in Spotify Developer.
After creating the view controller, our application is ready to use and here is the View Controller code snippet :
You will have to try the app on your phone as the app needs permission from spotify. It will not work in the simulator. You can browse here to use the application from your phone.
Congratulation!
We have completed our application, now you can use other functions of spotify sdk as you wish.
You will have to try the app on your phone as the app needs permission from spotify. It will not work in the simulator. You can browse here to use the application from your phone.
?Note: This article was written by ?mer F?rat , an iOS developer at Theatech ?mer F?rat , who is part of our iOS development team, is pleased to share the content of this article with our esteemed readers.
Content author: ?mer F?rat - iOS Developer
Chief Experience Officer @ Theatech | Product Owner @Qfix
1 年Well done ????
UI/UX Designer | Product Designer
1 年?? ??
Social Media Manager
1 年? ? ?