Ash-Bash32
Ash-Bash32

Reputation: 443

My Action Extension for iOS Not Showing Public.URL in the Debugger

Hi viewer I have a problem with my Action Extension for iOS where I'm trying to get the Public URL that Safari has opened currently but i can't tell if i have the Public URL since its not showing in the Debugger. Matter of Fact the Debugger is Black and the only information that shows is if the Action Extension gets interrupted/ crashes.

Heres my code that gets the Public.url from safari.

//get the itemProvider which wraps the url we need
    var item : NSExtensionItem = self.extensionContext!.inputItems[0] as! NSExtensionItem
    var itemProvider : NSItemProvider = extensionItem.attachments?.first as! NSItemProvider

    //pull the URL out
    if (itemProvider.hasItemConformingToTypeIdentifier("public.url")) {
        itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in
            let url : NSURL = urlItem as! NSURL
            //do what you need to do now, such as send a request to your server with this url
            println(url.absoluteString!);
        })
    }

Is there a better way of doing it its written in swift and Plus I've look around and couldn't find a better solution so I'm asking is there a tutorial or an example I can follow.

Upvotes: 1

Views: 824

Answers (1)

Mehmet
Mehmet

Reputation: 333

I believe the following would work:

    let item : NSExtensionItem = self.extensionContext!.inputItems[0] as! NSExtensionItem
    let itemProvider : NSItemProvider = item.attachments?.first as! NSItemProvider

    //pull the URL out
    if (itemProvider.hasItemConformingToTypeIdentifier("public.url")) {
        itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in
            let url : NSURL = urlItem as! NSURL
            //do what you need to do now, such as send a request to your server with this url
            print(url.absoluteString);
        })
    }

Upvotes: 1

Related Questions