Create a button
Within your Swift application in Xcode, loadContentView.swift. At the top of
the file you will see a struct for ContentView, within which is a basic
string that will be output to your iOS application if you run the app in an
emulator.
Text output line with a button to be able to trigger
off the call to get the current user. Replace that line with the below button.
Add an API call button action
When a user clicks the button, we want to fetch the user’s details. To achieve this we need to do two things, add the import for the Box iOS SDK and add the button action to make the call. At the top of theContentView.swift file, add import BoxSDK with the other
import statement.
Next, within the button action, where we currently have a comment placeholder,
add a call to the iOS SDK to fetch the current user. When the API call
completes it will print an authentication message to the developer console. For
ease of implementation, we have a blocking sleep(5) call in place in order to
test that the iOS SDK can make calls from our iOS SDK by providing enough time
for the request to complete.
Replace {{YOUR DEVELOPER TOKEN}} with your developer token.
If you don’t see the Xcode developer console, from the menu click View ->
Debug Area -> Activate Console
Summary
- You added a button to your blank iOS application
- You added a request to fetch the current user using the iOS SDK
