diff --git a/README.md b/README.md index c1353c0..6673893 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,17 @@ navigator.startApp.start([ function(error) { /* error */ console.log('47', error); }); -``` \ No newline at end of file +``` + + + +**Start application in iOS** + +```js +navigator.startApp.start("twitter://", function(message) { /* success */ + console.log(message); // => OK +}, +function(error) { /* error */ + console.log('47', error); +}); +``` diff --git a/plugin.xml b/plugin.xml index 1ba1be3..c7dbfcc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,4 +24,18 @@ + + + + + + + + + + + + + + diff --git a/src/ios/startApp.h b/src/ios/startApp.h new file mode 100644 index 0000000..a835f9a --- /dev/null +++ b/src/ios/startApp.h @@ -0,0 +1,8 @@ +#import + +@interface startApp : CDVPlugin + +- (void)check:(CDVInvokedUrlCommand*)command; +- (void)start:(CDVInvokedUrlCommand*)command; + +@end \ No newline at end of file diff --git a/src/ios/startApp.m b/src/ios/startApp.m new file mode 100644 index 0000000..b851344 --- /dev/null +++ b/src/ios/startApp.m @@ -0,0 +1,41 @@ +#import "startApp.h" +#import + +@implementation startApp + +- (void)check:(CDVInvokedUrlCommand*)command { + + CDVPluginResult* pluginResult = nil; + + NSString* scheme = [command.arguments objectAtIndex:0]; + + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:(true)]; + } + else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsBool:(false)]; + } + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + +} + +- (void)start:(CDVInvokedUrlCommand*)command { + + CDVPluginResult* pluginResult = nil; + + NSString* scheme = [command.arguments objectAtIndex:0]; + + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) { + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:scheme]]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:(true)]; + } + else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsBool:(false)]; + } + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + +} + +@end \ No newline at end of file