Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find Foundation.NSJavaScriptExtension class in app extension

I'm developping an app extension for iOS with Xamarin Studio. I tried to use a class that is supposed to be in the Foundation API, but I can't find it. The class is called NSJavaScriptExtension.

I tried to access it by specifying the namespace:

Foundation.NSJavaScriptExtension

I also tried to use the using directive:

using Foundation;

When I tried compiling it, I got the following error message:

Error CS0103: The name 'NSJavaScriptExtension' does not exist in the current context (CS0103)

This is really strange because the Xamarin documentation says that it exists.

Here's my code :

// Create an extension Item
var extensionItem = new NSExtensionItem ();
// Create a Final value Dictionary
var finalize = new NSMutableDictionary ();

finalize.Add (NSJavaScriptExtension.FinalizeArgumentKey, new NSString ("{bgColor:red}")); // <- here

// Create an item provider and attach it to the extension item
var provider = new NSItemProvider (finalize, MobileCoreServices.UTType.PropertyList);
extensionItem.Attachments = new NSItemProvider[]{ provider };

// Send results to the calling Host App
ExtensionHelper.ExtensionContext.CompleteRequest (new NSExtensionItem[]{ extensionItem },
(completionHandler) => {
    return;
});
like image 939
skyjetsen Avatar asked Jan 31 '26 07:01

skyjetsen


1 Answers

The type NSJavaScriptExtension was added in XI 9.0. The easiest way to get it is to upgrade to the latest stable release, which can target older iOS versions as well.

If you cannot update then you can load any constant manually at runtime, like:

using Foundation;
using ObjCRuntime;

...

IntPtr foundation = Dlfcn.dlopen (Constants.FoundationLibrary, 0);
NSString FinalizeArgumentKey = Dlfcn.GetStringConstant (foundation.Handle, "NSExtensionJavaScriptFinalizeArgumentKey");
like image 162
poupou Avatar answered Feb 02 '26 22:02

poupou