Initialization

Here is how to initialize the Wepin widget iOS SDK.

Then, use the App ID and App Key assigned after app registration to initialize the instance.

Initialize

Before using the created instance, initialize it using the App ID and App Key.

import wepin

let appId = "app_id_eg12sf3491azgs520"
let appKey = "ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313", 
let attributes = Wepin.WidgetAttributes(type: Wepin.WidgetType.show)

let attributes = Wepin.WidgetAttributes(type: Wepin.WidgetType.show)
let wepin = Wepin.instance()
wepin.initialize(appId: appId, appKey: appKey, attributes: attributes){ (result, error) -> Void in
    print(result)
}

WidgetAttributes, WidgetType

The WidgetAttributes and WidgetType, which are used as parameters for initialization, are as follows.

public enum WidgetType: String {
    case show
    case hide
}

public struct WidgetAttributes {
    var type: WidgetType
    var defaultLanguage: String
    var defaultCurrency: String
}
  • appId: String App ID assigned during registration

  • appKey: String App Key assigned during registration

  • attributes: Object (optional) Properties of the Wepin Widget

    • type: WidgetType It determines how the app widget window will be displayed on initial loading. The default value is hide. show: Show the widget window immediately after loading for the first time. hide: Hide the widget window initially when loading and show it later using openWidget().

    • defaultLanguage: String The language to be displayed on the widget. The default value is ko. The currently supported languages are en and ko.

    • defaultCurrency: String The currency to be displayed on the widget. The default value is KRW. The currently supported currencies are USD and KRW.

You need to handle the URL schemes added in the app's Info file in the AppDelegate or SceneDelegate. If your app has SceneDelegate, handle it there. Otherwise, add the following code to handle it int the AppDelegate.


// If you are adding it to AppDelegate, handle it here:
// func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool{ } 

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

    guard let url = URLContexts.first?.url else { return }
    let bundleId = Bundle.main.infoDictionary?[“CFBundleIdentifier”] as! String
    print(“bundleId ” + bundleId)
    let checkScheme = bundleId + “.wepin”
    // Check url scheme
    guard url.scheme == checkScheme else {
      print(“invalid url scheme :+ url.scheme!)
      return
    }
    // Pass the received URL to Wepin.
    Wepin.instance().handleUniversalLink(paramUrl: url)
    //
}

isInitialized

You can use the isInitialized method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

  • boolean init result; true if Wepin SDK is already initialized, otherwise false.

if(Wepin.isInitialized()) {
    // Success to initialize wepin
}

Last updated