しめ鯖日記

swift, iPhoneアプリ開発, ruby on rails等のTipsや入門記事書いてます

UIDocumentInteractionControllerを使ったファイル共有でCouldn't get file size for (null): (null)エラーが出た時の対処法

UIDocumentInteractionControllerはファイルを他のアプリに共有できる機能です。
以下のように記述すればポップアップが出てきてその中のどれかのアプリにファイルを送信する事ができます。
この機能を試している時、ファイルは存在しているはずなのに表題のエラーが出ました。

let url = NSURL(fileURLWithPath: "xxx.jpg")
let documentInteractionController = UIDocumentInteractionController(URL: url)
documentInteractionController.presentOptionsMenuFromRect(CGRect(), inView: view, animated: true)

原因はdocumentInteractionControllerがdeallocateされてた事でした。
documentInteractionControllerをローカル変数からインスタンス変数に直したら無事に動いてくれました。