How to use UIActivityViewController with MonoTouch

I am trying to access the 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) 

An iOS action sheet is displayed, but these actions are not excluded. Any suggestions what is the problem? Are there any MonoTouch samples for this?

+4
source share
1 answer

You were close. Change this:

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

in

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

Note. The name of a constant does not always match its value. In addition, it is common (even bad practice) for ObjC to compare NSString pointers (and not their values) to find constant equality - creating your own NSString instance will not work in such cases (in any case, exposed const look much better and work better with code completion from the IDE).

+5
source

Source: https://habr.com/ru/post/1445620/


All Articles