Different data for sharing providers in UIActivityViewController

前端 未结 4 1333
忘掉有多难
忘掉有多难 2020-12-01 02:32

I\'m trying to use an UIActivityViewController with one long NSString as the data. If I put a string > 140 characters, the tweet sheet in it does n

4条回答
  •  眼角桃花
    2020-12-01 02:42

    This can be easily done by using the optional activityType property from the UIActivityItemProvider object. That property returns a UIActivityType, so you can do something like:

    class PhotoActivityItemProvider: UIActivityItemProvider {  
        ...
    
        override var item: Any {
            guard let activityType = self.activityType else {
                return photoURL.absoluteString
            }
            if activityType == .mail || activityType == .message {
                return "The photo link is \(photoURL.absoluteString)."
            }
    
            ...
        }
    

    More information in my blog post: https://www.whitesmith.co/blog/control-what-youre-sharing/

提交回复
热议问题