Search code examples
iosobjective-ccrosswalk-runtimecrosswalk

Crosswalk extension not working in iOS


I am trying to make Crosswalk extension in iOS (Objective-C) for my own app which displays a website in Crosswalk runtime but it is not working. Following are the details:

  1. Created CocoaTouch framework project at the root of my main project which is single page application.
  2. Added the following code to the MyXWalkExtension.h file of my CocoaTouch framework project:

    #import <UIKit/UIKit.h>
    
    #import <XWalkView/XWalkView.h>
    
    //! Project version number for MyXWalkExtension.
    
    FOUNDATION_EXPORT double MyXWalkExtensionVersionNumber;
    
    //! Project version string for MyXWalkExtension.
    
    FOUNDATION_EXPORT const unsigned char MyXWalkExtensionVersionString[];
    
    @interface MyXWalkExtension : XWalkExtension
    
    @end
    
    @interface MyXWalkExtension ()
    
    - (void) jsfunc_myFunction:(UInt32*)callId message:(NSString *)myVariable;
    
    @end
    
    @implementation MyXWalkExtension
    
    - (void) jsfunc_myFunction:(UInt32*)callId message:(NSString *)myVariable {
    
    NSLog(@"MY VARIABLE: %@", myVariable);
    
    }
    
    @end
    
  3. Added extensions.plist (couldn't find better way to display .plist content) to CocoaTouch framework project as follows:

    <plist>
    
    <dict>
    
        <key>XWalkExtensions</key>
    
        <dict>
    
            <key>xwalk.myxwalkextension.MyXWalkExtension</key>
    
            <string>MyXWalkExtension</string>
    
        </dict>
    
    </dict>
    
    </plist>
    
  4. Added manifest.plist to the CocoaTouch framework project:

    <plist>
    
    <dict>
    
        <key>xwalk_extensions</key>
    
        <array>
    
            <key>item 0</key>
    
            <string>xwalk.myxwalkextension.MyXWalkExtension</string>
    
        </array>
    
    </dict>
    
    </plist>
    
  5. Calling from javascript as follows:

    xwalk.myxwalkextension.MyXWalkExtension.myFunction('100');
    

I checked whether the above javascript code's block is executing or not & it is executing, but am not getting log in my xcode logging console. Because I think that the jsfunc_myFunction is not getting called from javascript. I don't know what am I missing or doing wrong. I am following crosswalk project website. I know that we don't need to extend Crosswalk runtime in case of Android where we can call Android native methods from javascript by providing a javascript interface, but in iOS it is not the case. So, I decided to extend Crosswalk runtime. The crosswalk project website is not much descriptive & detailed. Am I forgetting to embed the extension in my project, if yes, how do I do it?


Solution

  • [XWalkExtensionFactory register:@"xwalk.myxwalkextension.MyXWalkExtension" cls:[MyXWalkExtension class]];
    //where xWalkView is XWalkView (Crosswalk's WebView).
    [self.xWalkView loadExtension:[XWalkExtensionFactory createExtension:@"xwalk.myxwalkextension.MyXWalkExtension"] namespace:@"xwalk.myxwalkextension.MyXWalkExtension"];
    

    I had to load my XWalkExtension & embed it into the app in ViewController.m.