Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

javascript - Is there a way to share specific app ios?

I'm using react native Share sheet. Currently, it shows a row of eligible apps to share to. However, I would like it to show only one app at a time. Namely, when I'm sharing to snapchat, have it only show snapchat so the user doesn't have to look for it in "More".

I know there's a way to exclude specific apps (https://developer.apple.com/documentation/uikit/uiactivity/activitytype):

onClick() {
  Share.share({
    message: 'BAM: we're helping your business with awesome React Native apps',
    url: 'http://bam.tech',
    title: 'Wow, did you see that?'
  }, {
    // Android only:
    dialogTitle: 'Share BAM goodness',
    // iOS only:
    excludedActivityTypes: [
      'com.apple.UIKit.activity.PostToTwitter'
    ]
  })
}

but i don't know the uiactivitytype signatures for all the apps i want to exclude (if you know please tell) but also it would be harder to blacklist everything than to whitelist just snapchat.

Is there a way to do this? Perhaps with includedActivityTypes?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's my list:

let vc = UIActivityViewController(activityItems: [shareImage], applicationActivities: [])
vc.excludedActivityTypes =  [
    //UIActivity.ActivityType.postToTwitter,
    //UIActivity.ActivityType.postToFacebook,
    UIActivity.ActivityType.postToWeibo,
    //UIActivity.ActivityType.message,
    //UIActivity.ActivityType.mail,
    //UIActivity.ActivityType.print,
    //UIActivity.ActivityType.copyToPasteboard,
    UIActivity.ActivityType.assignToContact,
    //UIActivity.ActivityType.saveToCameraRoll,
    UIActivity.ActivityType.addToReadingList,
    //UIActivity.ActivityType.PostToFlickr,
    UIActivity.ActivityType.postToVimeo,
    UIActivity.ActivityType.postToTencentWeibo,
    //UIActivity.ActivityType.airDrop,
    UIActivity.ActivityType.openInIBooks,
    UIActivity.ActivityType.markupAsPDF
]

Sorry for the brain dump, but in pretty much any version of Xcode (what follows is from 12.3) you can drill into things, and UIActivity.ActivityType yields:

extension UIActivity.ActivityType {

    @available(iOS 6.0, *)
    public static let postToFacebook: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let postToTwitter: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let postToWeibo: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let message: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let mail: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let print: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let copyToPasteboard: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let assignToContact: UIActivity.ActivityType

    @available(iOS 6.0, *)
    public static let saveToCameraRoll: UIActivity.ActivityType

    @available(iOS 7.0, *)
    public static let addToReadingList: UIActivity.ActivityType

    @available(iOS 7.0, *)
    public static let postToFlickr: UIActivity.ActivityType

    @available(iOS 7.0, *)
    public static let postToVimeo: UIActivity.ActivityType

    @available(iOS 7.0, *)
    public static let postToTencentWeibo: UIActivity.ActivityType

    @available(iOS 7.0, *)
    public static let airDrop: UIActivity.ActivityType

    @available(iOS 9.0, *)
    public static let openInIBooks: UIActivity.ActivityType

    @available(iOS 11.0, *)
    public static let markupAsPDF: UIActivity.ActivityType
}

I think that's what you want. As always, look for changes with an iOS release. (I tend to check every iOS release, but you never know.) Also, keep in mind that customizations can be done with share sheets.

Finally, note that it is a blacklist. That's how it is.

EDIT:

I was able to bring up my list because this is how it's coded in my apps. It's much easier to keep a FULL list of defined types, including those that are not blacklisted for future purposes!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...