Adding the SDK

Adding the SDK via Cocoapods

If you’re using Cocoapods, you can add the SDK by adding the dependency to your Podfile:

1
pod "KlarnaMobileSDK"

Followed by performing:

1
pod install

You should then be able to import the KlarnaMobileSDK module in your workaspace.

Adding the SDK via Carthage

If you’re using Carthage, you can add the SDK to your Cartfile as below:

1
github "klarna/klarna-mobile-sdk"

Followed by performing:

1
carthage update

You should be then able to add the .framework to your project.

Configure Your App

Return URL

Both the hybrid and native integrations might, at some point, open third-party applications. To automatically return the user, these third-party applications need to know about your app’s shema.

To do that, you’ll need to provide the SDK with what we call a “return URL” parameter. If you haven’t done so already, you can add the schema to your app’s plist.

Common Elements

Importing the SDK

Both the Klarna Payments native integration and the hybrid integration are available under the KlarnaMobileSDK module.

1
import KlarnaMobileSDK
1
#import <KlarnaMobileSDK/KlarnaMobileSDK-Swift.h>


A Common Class For Cross-cutting Concerns

Some features in the SDK are relevant for both native and hybrid integrations of the SDK. These are accessible under the CommonMobileSDKCommon class. These features are:

  • Setting a logging level.
  • Reading the device identifier.

1. Reading the Device Indentifier

You can read the device identifier with the static function deviceIdentifier() on your KlarnaMobileSDKCommon.

This device identifier is stored in user defaults.

Read the Identifier

1
KlarnaMobileSDKCommon.deviceIdentifier()
1
[KlarnaMobileSDKCommon deviceIdentifier];

2. Setting the Logging Level

The SDK will log events and errors to the system’s log while it’s running. You can read these through XCode’s console or the Console app in Mac OS. You can set the logging level for the SDK through the setLoggingLevel() static function on KlarnaMobileSDKCommon

Set Level

ParamTypeDescription
Param
loggingLevel
Type
KlarnaLoggingLevel
Description
The type of events or level the SDK should log at.

KlarnaLoggingLevel values:


NameDescription
Name
off / KlarnaLoggingLevelOff
Description
Nothing will be logged into console.
Name
error / KlarnaLoggingLevelError
Description
Only errors will be logged into console.
Name
verbose / KlarnaLoggingLevelVerbose
Description
Everything will be logged into console.
1
KlarnaMobileSDKCommon.setLoggingLevel(.verbose)
1
[KlarnaMobileSDKCommon setLoggingLevel: KlarnaLoggingLevelVerbose];