iOS Spotify SDK - Swift 5 Tutorial

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 !?????


Bu resim i?in metin sa?lanmad?







1 - Create A New XCode Project

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?

Then we need to add Objective-C File to our App.

Bu resim i?in metin sa?lanmad?

You can give the name you want, then we will delete it.

Bu resim i?in metin sa?lanmad?

This will then ask you if you want Xcode to create a bridging file for your. Say yes Create Bridging Header.

Bu resim i?in metin sa?lanmad?

Then delete the objective c file and only the bridging header file remains and add?#import <SpotifyiOS/ SpotifyiOS.h>?this code snippet.

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?

In the end it should look like this.

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?

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:

Bu resim i?in metin sa?lanmad?



We need to add our own keys to the places in the code. You can find it in dashboard in Spotify Developer.

Bu resim i?in metin sa?lanmad?
We have completed our application, now you can use other functions of spotify sdk as you wish.

After creating the view controller, our application is ready to use and here is the View Controller code snippet :

Bu resim i?in metin sa?lanmad?

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.

Bu resim i?in metin sa?lanmad?
Bu resim i?in metin sa?lanmad?
Bu resim i?in metin sa?lanmad?
Bu resim i?in metin sa?lanmad?
Bu resim i?in metin sa?lanmad?

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

Ay?e Sanc?l?

Chief Experience Officer @ Theatech | Product Owner @Qfix

1 年

Well done ????

回复
Sevilay Do?u

UI/UX Designer | Product Designer

1 年

?? ??

回复
Esmanur Deniz

Social Media Manager

1 年

? ? ?

回复

要查看或添加评论,请登录

Theatech的更多文章

社区洞察

其他会员也浏览了