不能从[UIActivityViewController excludedActivityTypes]

时间:2015-05-06 13:42:48

标签: ios objective-c facebook uikit uiactivityviewcontroller

我希望创建一个UIActivityViewController,它将排除一些本地共享功能,包括Facebook和Twitter Share。但Facebook的份额仍以ShareExtention的形式提供。

我创建了以下内容:

activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems  applicationActivities:applicationActivities];

并通过设置排除的活动类型排除Facebook。

activityViewController.excludedActivityTypes = @[
                                                 UIActivityTypeAddToReadingList,
                                                 UIActivityTypeAssignToContact,
                                                 UIActivityTypePrint,
                                                 UIActivityTypeSaveToCameraRoll,
                                                 UIActivityTypeCopyToPasteboard,
                                                 UIActivityTypeAirDrop,
                                                 UIActivityTypePostToFacebook,
                                                 UIActivityTypePostToTwitter
                                                 ];

在我的iPhone上运行时,尽管排除了Facebook图标,但仍会显示。

调查这是如何发生的我发现活动控制器的完成处理程序返回activityType = com.facebook.Facebook.ShareExtension,而不是UIActivityTypePostToFacebook。此外,当在活动控制器中选择更多按钮时,Facebook的切换与使用共享约定的其他应用程序一样。

为什么Facebook在Twitter不使用时会使用shareExtention,为什么我不能使用排除的活动将其排除?

注意:我已在多台设备上对此进行了测试,但该问题仅存在于运行8.1.3的设备上。

由于

2 个答案:

答案 0 :(得分:5)

试试这种方式

// sharing items in an array lets say sharingItems
NSArray *sharingItems = @[@"hello", @"how", @"are", @"You."];

//making UIActivityViewController object lets say avc
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

//exclude UIActivityTypePostToFacebook 
avc.excludedActivityTypes = @[UIActivityTypePostToFacebook];

//presenting UIActivityViewController in our case avc
[self presentViewController:avc animated:YES completion:nil];

见下图,Facebook不包括

In image Facebook not included

评论avc.excludedActivityTypes = @[UIActivityTypePostToFacebook]; Facebook再次在共享选项中可见

When commenting  avc.excludedActivityTypes = @[UIActivityTypePostToFacebook]; Facebook again becomes visible in share option

答案 1 :(得分:0)

//Hope this helps . This is how it is done in Swift 3.

  //  When Including the FB Option the code is as follow:

      func otherSharing() {

            let activityItem: [AnyObject] = [returnFinalImage() as AnyObject]


            let avc = UIActivityViewController(activityItems: activityItem as [AnyObject], applicationActivities: nil)
             avc.excludedActivityTypes = [UIActivityType.addToReadingList, UIActivityType.assignToContact, UIActivityType.print, UIActivityType.saveToCameraRoll, UIActivityType.copyToPasteboard, UIActivityType.airDrop, UIActivityType.postToTwitter]
            self.present(avc, animated: true, completion: nil)
        }

    //When Excluding the FB Option the code is as follow:

        func otherSharing() {

            let activityItem: [AnyObject] = [returnFinalImage() as AnyObject]


            let avc = UIActivityViewController(activityItems: activityItem as [AnyObject], applicationActivities: nil)
             avc.excludedActivityTypes = [UIActivityType.addToReadingList, UIActivityType.assignToContact, UIActivityType.print, UIActivityType.saveToCameraRoll, UIActivityType.copyToPasteboard, UIActivityType.airDrop, UIActivityType.postToFacebook, UIActivityType.postToTwitter]
            self.present(avc, animated: true, completion: nil)
        }

    //I have Added Screen shot : [![enter image description here][1]][1]


      [1]: https://i.stack.imgur.com/IGzqC.jpg