Reputation: 97
I have tried to search this but haven't really found what I was looking for. It appears the "child browser" plugin might have done what I wanted, but it appears to be depreciated.
I have a phonegap based project, but Id like to have an in-app settings page that interacts with the settings bundle that doesn't appear to be possible with phonegap itself.
Is there a way to create a viewcontroller in xcode that would be the settings page and be able to access it via phonegap?
Any thoughts would be appreciated.
Noel
Upvotes: 0
Views: 268
Reputation: 23893
You need to use cordova.exec API to communicate between native functionality and hybrid app.
make sure you already define your plugin in your config.xml
<feature name="CustomPlugin">
<param name="ios-package" value="CustomPlugin" />
</feature>
Implementing the plug-in by using Objective-C code
CustomPlugin.h
#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
@interface CustomPlugin : CDVPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command;
@end
CustomPlugin.m
#import "CustomPlugin.h"
@implementation CustomPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command{
NSString *responseString =
[NSString stringWithFormat:@"Hello World, %@", [command.arguments objectAtIndex:0]];
CDVPluginResult *pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
Calling a plug-in from JavaScript
function initial(){
var name = $("#NameInput").val();
cordova.exec(sayHelloSuccess, sayHelloFailure, "CustomPlugin", "sayHello", [name]);
}
function sayHelloSuccess(data){
alert("OK: " + data);
}
function sayHelloFailure(data){
alert("FAIL: " + data);
}
Upvotes: 1