Skip to content

Instantly share code, notes, and snippets.

@abadikaka
Created April 24, 2020 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abadikaka/9047d513fec4e1c3f2b72716fc814ff7 to your computer and use it in GitHub Desktop.
Save abadikaka/9047d513fec4e1c3f2b72716fc814ff7 to your computer and use it in GitHub Desktop.
ShareViewController ShareKitTutorial
//
// ShareViewController.swift
// SharingExtension
//
// Created by Michael Abadi Santoso on 1/28/20.
// Copyright © 2020 Michael Abadi Santoso. All rights reserved.
//
import UIKit
import StorageKitTutorial
import NetworkKitTutorial
import SwiftUI
/// Mocking Request class for the networking call
final class Request: NetworkBaseRequest {
var params: [String : Any]? = nil
var endpoint: String {
return "v1/api/request"
}
}
/// Share Extention main view
final class ShareViewController: UIViewController {
private let storage = StorageKit(type: .sharing)
private let network = NetworkKit()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupToken()
}
/// Initialize the token from the main app and the extention take the token from main app
private func setupToken() {
if let token = storage.loadToken() as? String {
network.setupAuthentification(withToken: token)
print("TOKEN : \(token)")
}
}
@IBSegueAction func addView(_ coder: NSCoder) -> UIViewController? {
return UIHostingController(coder: coder, rootView: ShareContentView())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment