AirDrop

330 阅读1分钟

前几天碰到个需求 需要在AirDrop中出现自己的app 经过几个小时的查资料 大致知道怎么回事了 实现起来也很简单 流程如下

Targets -> Info -> Document Type 中

AirDrop.png

UTI根据项目需要在https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html 中自己选择

测试代码 AppDelegate.swift

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
  print(url)
  print(options)
  let controller = ViewController()
  controller.fileURL = url
  self.window?.rootViewController = UINavigationController(rootViewController: controller)
        return true
}

ViewController.swift

class ViewController: UIViewController {
    var fileURL: NSURL!
    override func viewDidLoad() {
        super.viewDidLoad()
        let label = UILabel(frame: UIScreen.mainScreen().bounds)
        self.view.addSubview(label)
        label.numberOfLines = 0
        label.backgroundColor = UIColor.redColor()
        if self.fileURL != nil {
            label.text = String(self.fileURL!)
        }
    }
}

最重要的是 AirDrop 模拟器是没有作用的 必须真机调试才可以!!!