Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
My info
Plan: Premium
Country: Belgium
Device: iPhone 11 Pro Max
Operating System: iOS 13.5 + macOS Catalina
Dear all
I installed and the iOS SDK properly in Xcode and set up the server token swap and refresh properly => demo swift login works nicely.
Now I'm trying to integrate that into my iOS application and it doesn't work at all. I tested everything that was possible and I broke it down to the least changes to the demo to better understand what could cause it to fail. See hereunder:
1) I set up a basic Xcode iOS app
2) I don't use create the views using programmation as in your demo, I use the Storyboard (only difference with the demo code)
3) I set everything exactly the same, it builds and it runs on the iPhone device nicely without any error or any alert message
4) when I click "Connect", it asks permission to use "Spotify" as expected, I answer yes, it switches to Spotify and starts playing the song
5) it switches back to my app and still shows the "Connect" button
When debugging, I set up breakpoints at every sessionManager, application methods and appRemote event functions, none of them is apparently caught.
When I do the same in the demo project, it stops at breakpoints
My conclusions:
- the delegates do not work and seem not to be assigned correctly because no event is caught
What is strange? It's line per line EXACTLY the same code as the demo project, only I use Scenes so I have a SceneDelegate.swift file in my project.
I tried to transfer some of the code like the delegate assignment to the SceneDelegate file to the corresponding events but it doesn't work well and the openURL method is not the same as in the application open url method so I don't know how to translate the openURL call at scene level.
I'm lost, I spent 3 days trying everything and nothing works. BTW, I use regularly the Web API without any problem so I understand pretty well the Spotify auth process.
Can anybody help me? Because the iOS examples, to be honest, they are pretty thin to find solutions. Can't you at least have one example that uses the StoryBoard or SwiftUI, building the views programmatically do not really help people that want to start programming.
Or at least give me tips please, I'm stuck..
thx a lot, Nico
Solved! Go to Solution.
Hi Ouml
Fantastic, it works fine now.
Just another problem now, it seems that my IBOutlets are not accessible when the interface has to be refreshed with the playing song.
I instantiate the Viewcontroller in SceneDelegate and keep a reference as follows:
let rootViewController : ViewController = {
return (UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "ViewController") as? ViewController)!
}()
I have outlets as such:
@IBOutlet weak var imgCover: UIImageView!
@IBOutlet weak var btnPausePlay: UIButton!
@IBOutlet weak var lblTrack: UILabel!
@IBOutlet weak var btnConnect: UIButton!
@IBOutlet weak var btnDisconnect: UIButton!
The outlets are connected and they are accessible when I am in viewDidLoad function of the view controller.
But, as soon as I want to change them in other functions, it returns "
Fatal error: Unexpectedly found nil while unwrapping an Optional value"
As if the outlets are not initialised in the class (although using self. )
What is strange is that the initialise above is called TWICE when I debug, I have the feeling that I have two instances of the same view controller active at some points
Well, that's another issue, thanks for your precious help
Add a log in File ViewController->ViewDidLoad() to see whether the ViewController has been init twice.
If Yes, Check [General]->[Deployment Info]->"Main Interface". Has the value of this option been removed?
If not this problem, which func do you put your init code in? Try to find why it has been init twice.
You forget one thing in AppDelegate.m. Add the code to process the response from spotify. After this process , delegate of sessionManager will be called.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
rootViewController.sessionManager.application(app, open: url, options: options)
return true
}
Well, thanks for the reply but actually it's a storyboard scene so that method is never called, only the equivalent ini SceneDelegate.swift is called.
Hi Ouml
Fantastic, it works fine now.
Just another problem now, it seems that my IBOutlets are not accessible when the interface has to be refreshed with the playing song.
I instantiate the Viewcontroller in SceneDelegate and keep a reference as follows:
let rootViewController : ViewController = {
return (UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "ViewController") as? ViewController)!
}()
I have outlets as such:
@IBOutlet weak var imgCover: UIImageView!
@IBOutlet weak var btnPausePlay: UIButton!
@IBOutlet weak var lblTrack: UILabel!
@IBOutlet weak var btnConnect: UIButton!
@IBOutlet weak var btnDisconnect: UIButton!
The outlets are connected and they are accessible when I am in viewDidLoad function of the view controller.
But, as soon as I want to change them in other functions, it returns "
Fatal error: Unexpectedly found nil while unwrapping an Optional value"
As if the outlets are not initialised in the class (although using self. )
What is strange is that the initialise above is called TWICE when I debug, I have the feeling that I have two instances of the same view controller active at some points
Well, that's another issue, thanks for your precious help
Add a log in File ViewController->ViewDidLoad() to see whether the ViewController has been init twice.
If Yes, Check [General]->[Deployment Info]->"Main Interface". Has the value of this option been removed?
If not this problem, which func do you put your init code in? Try to find why it has been init twice.
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…