UIActivityViewControllerCompletionHandler How to?

后端 未结 5 1743
予麋鹿
予麋鹿 2021-02-02 10:05

I am trying to use the UIActivityViewControllerCompletionHandler , but i dont quite get how..

I want to detect when the user finishes or dismisses this

5条回答
  •  醉梦人生
    2021-02-02 10:53

    For Swift, this one works for me...

        // Configure UIActivityViewController
        let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        activityViewController.excludedActivityTypes = [UIActivityTypeAirDrop,
            UIActivityTypeAddToReadingList,
            UIActivityTypeAssignToContact,
            UIActivityTypePrint,
            UIActivityTypeCopyToPasteboard]
    
        // Show UIActivityViewController
        presentViewController(activityViewController, animated: true, completion: nil)
    
        // Define completion handler
        activityViewController.completionWithItemsHandler = doneSharingHandler
    
    ...
    
    func doneSharingHandler(activityType: String!, completed: Bool, returnedItems: [AnyObject]!, error: NSError!) {
    
        // Return if cancelled
        if (!completed) {
            return
        }
        // If here, log which activity occurred
        println("Shared video activity: \(activityType)")
    }
    

提交回复
热议问题