Start a new topic

Setting up Plugins with Swift

We have a Plugin written in C++ for Wikitude. It works in Android when we implement it, however we are running into a problem with iOS, specifically swift.

The `ArchitectView` in Swift doesn't have the function `registerPlugin` that apparently is called in the Obj-C examples.

At first we thought that was because we didn't import `WTArchitectView+Plugins.h`, as described in the documentation. But, using

#import <WikitudeSDK/WTArchitectView+Plugins.h

in the "Bridging Header" doesn't help either.

Can anyone tell us what we could do to get access to the `registerPlugin` function?



1 Comment

Hi Tom,

for this I would like to refer you to the native SDK package. The Swift sample project contained therein does register several plugins. It does so by creating an Objective C wrapper function that is then called from Swift. Here are the relevant excerpts for the barcode plugin.

@interface BarcodePluginWrapper ()
@property (nonatomic, assign) std::shared_ptr<BarcodePlugin>                plugin;

@implementation BarcodePluginWrapper

- (id)initWithCameraWidth:(int)cameraWidth :(int)cameraHeight :(WTBarcodePluginViewController *) viewController
    self = [super init];
    if (self)
        _plugin = std::make_shared<BarcodePlugin>(cameraWidth, cameraHeight, viewController);
    return self;

- (void)registerPluginWithSDK:(WTWikitudeNativeSDK *)sdk;
    NSError *error = nil;
    BOOL pluginRegistered = [sdk registerPlugin:_plugin error:&error];
    if ( !pluginRegistered )
        NSLog(@"Unable to register plugin '%@'. Error: %@", [NSString stringWithUTF8String:_plugin->getIdentifier().c_str()], [error localizedDescription]);

- (void)removePluginFromSDK:(WTWikitudeNativeSDK *)sdk
    [sdk removePlugin:_plugin];


self.barcodePlugin.registerPlugin(with: self.wikitudeSDK)

- Daniel

Login or Signup to post a comment