【问题标题】:Why IONIC/ Cordova SMS plugin takes time to load for the first time?为什么 IONIC/ Cordova SMS 插件第一次加载需要时间?
【发布时间】:2021-04-30 10:22:49
【问题描述】:

我安装了https://ionicframework.com/docs/native/sms 用于从 IONIC 应用程序发送短信。以下是我的实现:

sendSMS(phoneNumber: string, text: string, event) {
    this.sms.send(String(phoneNumber), text).then(result => {
        console.log(result);
    }).catch(error => {
        console.log(error);
    });
}

我正在 iOS 物理设备上对此进行测试。当我在全新安装后第一次单击按钮发送短信时,加载最多需要 30 秒,但在那之后,它会立即发生。即使在关闭应用程序并重新启动手机后。我查看了日志,发现:

文件:xxxx/ios/capacitor-cordova-ios-plugins/sources/CordovaSmsPlugin/Sms.m: 运行时:从后台线程调用的 UI API:-[UIViewController init] 只能在主线程中使用

Angular 11 版,IONIC 5.31.1 版,SMS ionic-native/sms": "^5.31.1", "cordova-sms-plugin": "^1.0.0"

【问题讨论】:

    标签: ios cordova ionic-framework


    【解决方案1】:

    文本编辑器需要从主线程运行。为此,请使用异步调度包装 composer 的启动。

    文件:src/ios/Sms.m

    dispatch_async(dispatch_get_main_queue(), ^{
    
    MFMessageComposeViewController *composeViewController = [[MFMessageComposeViewController alloc] init];
    composeViewController.messageComposeDelegate = self;
    
    NSString* body = [command.arguments objectAtIndex:1];
    if (body != nil) {
        BOOL replaceLineBreaks = [[command.arguments objectAtIndex:3] boolValue];
        if (replaceLineBreaks) {
            body = [body stringByReplacingOccurrencesOfString: @"\\n" withString: @"\n"];
        }
        [composeViewController setBody:body];
    }
    
    NSMutableArray* recipients = [command.arguments objectAtIndex:0];
    if (recipients != nil) {
        if ([recipients.firstObject isEqual: @""]) {
            [recipients replaceObjectAtIndex:0 withObject:@"?"];
        }
        
        [composeViewController setRecipients:recipients];
    }
    
    [self.viewController presentViewController:composeViewController animated:YES completion:nil];
    });
    

    查看此处了解更多信息: https://github.com/cordova-sms/cordova-sms-plugin/issues/218

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多