4

I am trying to access UIActivityViewController from MonoTouch with the following code:

var textToShare = new NSString("hallo there");
var activityItems = new NSObject[] {textToShare};
var excludedActivityTypes = new NSString[] { new NSString("UIActivityTypePostToWeibo"),       new NSString("UIActivityTypeMessage") };
var activityViewController = new UIActivityViewController(activityItems, null);
activityViewController.ExcludedActivityTypes = excludedActivityTypes;
this.PresentViewController(activityViewController, true, null)

The iOS action sheet is displayed but the specified activities are not excluded. Any suggestions what the problem is? Are there any MonoTouch samples for this?

poupou
  • 43,413
  • 6
  • 77
  • 174
user1819208
  • 41
  • 1
  • 3

1 Answers1

6

You were close. Change this:

var excludedActivityTypes = new NSString[] { 
    new NSString("UIActivityTypePostToWeibo"),
    new NSString("UIActivityTypeMessage") 
};

into:

var excludedActivityTypes = new NSString[] {
    UIActivityType.PostToWeibo,
    UIActivityType.Message
};

Note: The name of the constant is not always identical to it's value. Also it's common (even if bad practice) for ObjC to compare the NSString pointers (not their values) to detect constant equality - creating your own NSString instance won't work in such cases (anyway the exposed const are much better looking and work better with code completion from the IDE).

poupou
  • 43,413
  • 6
  • 77
  • 174
  • This was what I needed. I knew there was something wrong with the strings pointers but I couldn't find the the correct const. Thanks. – user1819208 Nov 13 '12 at 06:40
  • 1
    @user1819208 Great. Please take the time to mark the question as answered so other people, looking for the same/similar, question can see an answer is available. Welcome to SO! – poupou Nov 13 '12 at 12:58
  • how we can include linkedin in ExcludedActivityTypes? – user2021837 Sep 05 '17 at 02:08