rohfosho / CordovaCallNumberPlugin

Call a number directly from your cordova application.
MIT License
185 stars 151 forks source link

Slow first run #78

Open Freddycool opened 4 years ago

Freddycool commented 4 years ago

We use angular 7.2, IOS 11. On first click phone call - big delay 10 sec, after that all works fine

brunodelsing commented 4 years ago

I have the same problem right now.. Has anyone already found a solution?

davidseek commented 4 years ago

The problem is, that the process is called from wrong thread

Screen Shot 2020-02-14 at 12 50 41 PM

Wrapping everything to main queue fixes it:

#import <Cordova/CDVPlugin.h>
#import "CFCallNumber.h"

@implementation CFCallNumber

- (void) callNumber:(CDVInvokedUrlCommand*)command {

    [self.commandDelegate runInBackground:^{

        dispatch_async(dispatch_get_main_queue(), ^{

            CDVPluginResult* pluginResult = nil;
            NSString* number = [command.arguments objectAtIndex:0];
            number = [number stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

            if( ! [number hasPrefix:@"tel:"]){
                number =  [NSString stringWithFormat:@"tel:%@", number];
            }

            if(![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:number]]) {
                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];

        });

    }];
}

@end

So we store the patched CFCallNumber.m file locally and in our CI we're then replacing the Pods's file with out patched version. Works just fine.

idroxid commented 4 years ago

Hi @davidseek , just tried your solution and it works well. Do you plan to PR this ? Many thanks

Edit: Actually there is already a fix. I just installed the latest commit as I was unable to install it with npm install. I did it running: npm install github:rohfosho/CordovaCallNumberPlugin#33ec0d2554266869ad04ccdefb79fbab10614109

nicholaspearson commented 3 years ago

@rohfosho - please could you look into merging commit #33ec0d2554266869ad04ccdefb79fbab10614109 into master?

My app depends on it :)