NSItemProvider オブジェクトで loadItemForTypeIdentifier:options:completionHandler: メソッドを使用して、iOS 8 の共有拡張機能を介して Safari から URL を抽出しています。
Objective-C では、このコードと動作し、ブロックが実行されます。
[itemProvider loadItemForTypeIdentifier:(@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
//My code
}];
Swift では非常に似ていますが、クロージャーは実行されません。また、 itemProvider.hasItemConformingToTypeIdentifier("public.url")
が返さYES
れるため、 内から URL を解析するには有効なオブジェクトが必要ですitemProvider
。
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in
//My code
})
Info.plist NSExtension 部分は、Objective-C と Swift の両方のバージョンでまったく同じで、次のようになります。
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionPointName</key>
<string>com.apple.share-services</string>
<key>NSExtensionPointVersion</key>
<string>1.0</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
</dict>
私は何を間違っていますか?