Question

Is there a service or parameter I am missing to create the "Copy Link" button as seen in Apple's 12 Days app?

I am able to get the Copy button to appear by allowing

UIActivityTypeCopyToPasteboard

in my UIActivityViewController, and passing it a URL

NSURL *activityURL = [NSURL URLWithString:@"http://www.mylink.com/"];

It functions fine, but the button title is "Copy", which is not as clear as "Copy Link". I'm wondering if forcing this title is a service option I've missed, or requires defining a custom activity type. As far as I can tell, activityTitle is only available if you subclass the service method.

Thanks for any insight.

enter image description here

Was it helpful?

Solution 2

You'll have to make your own subclass due to the way the activity view controller's handle displaying options, unfortunately. :\

OTHER TIPS

I know it is old thread. Here is the answer. Subclass UIActivity and copy in pasteboard only of one of the items is URL here is the full implementation.

private var url = NSURL()

override func activityType() -> String? {
    return "com.productHunt.copyLink"
}

override func activityTitle() -> String? {
    return "Copy Link"
}

override func activityImage() -> UIImage? {
    return UIImage(named: "icon-copy")
}

override func canPerformWithActivityItems(activityItems: [AnyObject]) -> Bool {
    for activityItem in activityItems {
        if let _ = activityItem as? NSURL {
            return true
        }
    }

    return false
}

override func prepareWithActivityItems(activityItems: [AnyObject]) {

    for activityItem in activityItems {
        if let url = activityItem as? NSURL {
            self.url = url
        }
    }
}

override func performActivity() {
    UIPasteboard.generalPasteboard().string = url.absoluteString
    activityDidFinish(true)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top