Entry points specific to Service plugins

Service plugins are a generic type of plugin that can write code in the exported app's main context.

publishedInteractActions

See discussion of equivalent for Element plugins.

pluginAllowsMultipleInstances

Indicates whether there can be more than one instances of the plugin in a project.

Example:

this.pluginAllowsMultipleInstances = true;

getIOSInfoPlistProperties

Must return an object containing keys and values to be written to the exported project's info.plist file.

Example:

this.getIOSInfoPlistProperties = function() {
  return {
    "NSCameraUsageDescription": {
      "type": "string",
      "value": "Photos can be used within the app"
    }
  };
}

getIOSEntitlementsProperties

Must return an object containing keys and values to be written to the exported project's .entitlements file.

Example:

this.getIOSEntitlementsProperties = function() {
  return {
    "aps-environment": {
      "type": "string",
      "value": "development"
    }
  };
}

getIOSAppDelegateImports

Called to write any additional imports to be written to the exported project's AppDelegate class. Must return an array.

Example:

this.getIOSAppDelegateImports = function() {
  return ['"MyService.h"'];
}

getIOSAppDelegateProtocols

Called for any additional protocols to be added to the AppDelegate's interface in the exported project. Must return an array.

Example:

this.getIOSAppDelegateProtocols = function() {
  return ["MyServiceDelegate"];
}

writeIOSClasses(exporter)

Called to write any additional Objective-C classes.

Example:

this.writeIOSClasses = function(exporter) {
  var className = "MyService";
  exporter.writeSourceCode(className+".h", "@interface "+className+"\n@end");
  exporter.writeSourceCode(className+".m", "#include \""+className+".h\"\n@implementation "+className+"\n@end");
}

getIOSCustomAppDelegateMethodDeclarations(exporter)

Called to write any additional methods to the exported project's AppDelegate class. Must return an array. This function should be used together with writeIOSCodeForAppDelegateMethod function. Together they allow multiple plugins to write same methods without overlapping with each other. This is very useful when writing some common methods such as the methods declared in the UIApplicationDelegate protocol.

Example:

this.getIOSCustomAppDelegateMethodDeclarations = function(exporter) {
  return [
    " - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken",
    " - (void)doSomethingWith:(NSString *)str"
  ];
}

writeIOSCodeForAppDelegateMethod(methodName, exporter)

Called to write implementation for the methods declared in the getIOSCustomAppDelegateMethodDeclarations function. Values passed as methodName parameters follow the simplified form of the method declarations (without types and variable names). In addition to the custom methods declared in the plugin there are few methods which are called by default: didFinishLaunchingWithOptions, willResignActive, didEnterBackground, willEnterForeground, didReceiveMemoryWarning, didBecomeActive and willTerminate.

Example:

this.writeIOSCodeForAppDelegateMethod = function(methodName, exporter) {
  if (methodName == "application:didRegisterForRemoteNotificationsWithDeviceToken:") {
    return "// do something";
  }
  else if (methodName == "doSomethingWith:") {
    return "// do something";
  }
}

writeIOSCustomAppDelegateInterfaceCode(exporter)

Called to write any additional properties to the interface of the exported project's AppDelegate class.

Example:

this.writeIOSCustomAppDelegateInterfaceCode = function(exporter) {
  return "@property (nonatomic) MyService *myService;\n";
}

writeIOSCustomAppDelegateImplementationCode(exporter)

Called to write any additional methods to the implementation of the exported project's AppDelegate class.

this.writeIOSCustomAppDelegateImplementationCode = function(exporter) {
  return ""
  +"- (void)myServiceMethod:(MYService *)service\n"
  +"{\n"
  +"    // do something\n"
  +"}\n";
}

writeIOSCodeForPublishedInteractAction(actionId, exporter, varName, arg)

See discussion of equivalent for Element plugins.

libraryDependenciesInExportedProject_iOS

See discussion of equivalent for Element plugins.

getIOSEmbeddedBinaries

See discussion of equivalent for Element plugins.

getIOSModuleImports(exporter)

See discussion of equivalent for Element plugins.

getAndroidApplicationImports(exporter)

Called to write any additional import to the exported project's Application class. Must return an array.

Example:

this.getAndroidApplicationImports = function(exporter) {
  return [
    'android.app.AlertDialog'
  ];
}

getAndroidApplicationInterfaces

Called to write any additional interfaces the exported project's Application class would be implementing. Must return an array.

Example:

this.getAndroidApplicationInterfaces = function() {
  return ['Application.ActivityLifecycleCallbacks'];
}

writeAndroidClasses(exporter)

Called to write any additional Java classes.

Example:

this.writeAndroidClasses = function(exporter) {
  var className = "MyService";
  exporter.writeSourceCode(className+".java", "package "+exporter.getPackageName()+";\npublic class "+className+" {\n}");
}

writeAndroidCodeForApplicationMethod(methodName, exporter)

Called to write additional code to the existing methods in the exported project's Application class. Supported methods are (passed as values to the methodName parameter): onCreate and onTrimMemory.

Example:

this.writeAndroidCodeForApplicationMethod = function(methodName, exporter) {
  if (methodName == "onCreate") {
    return ""
      + "// do something\n";
  }
}

writeAndroidCodeForPublishedInteractAction(actionId, exporter, varName, arg)

See discussion of equivalent for Element plugins.

libraryDependenciesInExportedProject_Android

See discussion of equivalent for Element plugins.

writeAndroidCustomApplicationVariables(exporter)

Called to write any additional fields to the exported project's Application class.

Example:

this.writeAndroidCustomApplicationVariables = function(exporter) {
  return "public MyService myService;\n";
}

writeAndroidCustomApplicationMethods(exporter)

Called to write any additional methods to the exported project's Application class.

Example:

this.writeAndroidCustomApplicationMethods = function(exporter) {
  return ""
    +"private void myServiceMethod(MyService service) {\n"
    +"    // do something\n"
    +"}\n";
}