You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemmhmg/Mohem/plugins_/call-number/src/ios/CFCallNumber.m

48 lines
1.6 KiB
Objective-C

#import <Cordova/CDVPlugin.h>
#import "CFCallNumber.h"
@implementation CFCallNumber
+ (BOOL)available {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]];
}
- (void) callNumber:(CDVInvokedUrlCommand*)command {
[self.commandDelegate runInBackground:^{
CDVPluginResult* pluginResult = nil;
NSString* number = [command.arguments objectAtIndex:0];
number = [number stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if( ! [number hasPrefix:@"tel:"]){
number = [NSString stringWithFormat:@"tel:%@", number];
}
if(![CFCallNumber available]) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"NoFeatureCallSupported"];
}
else if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]]) {
// missing phone number
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"CouldNotCallPhoneNumber"];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
// return result
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
- (void) isCallSupported:(CDVInvokedUrlCommand*)command {
[self.commandDelegate runInBackground: ^{
CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:[CFCallNumber available]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
@end