68 lines
1.5 KiB
Swift
68 lines
1.5 KiB
Swift
//
|
|
// CopyDeepLinkActivity.swift
|
|
// Hthik
|
|
//
|
|
// Created by Hthik on 8/5/19.
|
|
// Copyright © 2019 Hthik. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UIActivity.ActivityType
|
|
{
|
|
static let copyDeepLink = UIActivity.ActivityType("com.rileytestut.Delta.CopyDeepLink")
|
|
}
|
|
|
|
class CopyDeepLinkActivity: UIActivity
|
|
{
|
|
private var deepLink: URL?
|
|
|
|
override class var activityCategory: UIActivity.Category {
|
|
return .action
|
|
}
|
|
|
|
override var activityType: UIActivity.ActivityType? {
|
|
return .copyDeepLink
|
|
}
|
|
|
|
override var activityTitle: String? {
|
|
return NSLocalizedString("Copy Deep Link", comment: "")
|
|
}
|
|
|
|
override var activityImage: UIImage? {
|
|
return UIImage(symbolNameIfAvailable: "link") ?? UIImage(named: "Link")
|
|
}
|
|
|
|
override func canPerform(withActivityItems activityItems: [Any]) -> Bool
|
|
{
|
|
if activityItems.contains(where: { $0 is Game })
|
|
{
|
|
return true
|
|
}
|
|
else
|
|
{
|
|
return false
|
|
}
|
|
}
|
|
|
|
override func prepare(withActivityItems activityItems: [Any])
|
|
{
|
|
guard let game = activityItems.first(where: { $0 is Game }) as? Game else { return }
|
|
|
|
self.deepLink = URL(action: .launchGame(identifier: game.identifier))
|
|
}
|
|
|
|
override func perform()
|
|
{
|
|
if let deepLink = self.deepLink
|
|
{
|
|
UIPasteboard.general.url = deepLink
|
|
self.activityDidFinish(true)
|
|
}
|
|
else
|
|
{
|
|
self.activityDidFinish(false)
|
|
}
|
|
}
|
|
}
|