私はXamarinのプロジェクトをやっている、フォームにウィンドウの階層ではなく、私は私のアプリからSMSを送信するためにXam.Plugins.Messagingを統合しています。このために、私は以下のコードで自分のiOSプロジェクトでカスタムレンダラを作成しました:警告:ビューがXamarin.Forms
AppDelegate smsObj = new AppDelegate();
bool a= smsObj.ShowAndSendSMS(new string[] { "123" }, "Hi there");
そして、私AppDelegateで、私は以下のようにコードを持っている:
public bool ShowAndSendSMS(string[] recipients, string body)
{
UIViewController sms = new UIViewController();
if (MFMessageComposeViewController.CanSendText)
{
MFMessageComposeViewController message = new MFMessageComposeViewController();
message.Finished += (sender, e) => {
message.DismissViewController(true, null);
};
message.Body = body;
message.Recipients = recipients;
sms.PresentModalViewController(message, false);
}
return true;
}
私が直面しています問題は上にあるが、私の最初のアプリの起動時に、SMSを共有する機能が動作せず、デバッグログに「ビューがウィンドウ階層に表示されないようにしようとしました!
私はアプリを再起動する場合は、同じ機能が魔法のように動作します。私が間違っていたところからのアイデア?
あなたが行く:https://www.dropbox.com/s/ncd9r2za3voeewu/AppDelegate.cs?dl=0 –
ありがとう!また、どこでAppDelegate smsObj =新しいAppDelegate()行ですか?別のAppDelegateインスタンスを新しくするべきではありません。 ShowAndSendSMSをいくつかのSMSヘルパークラスにリファクタリングするか、MonoがスピンアップするAppDelegateインスタンスを保持する静的なシングルトンを作成し、コード全体でその参照を使用できます。個人的には、私はSMSのヘルパークラスと責任の分離の観点から行きたいと思います。 –
私は私のiOSプロジェクトでカスタムレンダラーを作成して、次のようにAppDelegateのインスタンスを作成しています: 'public class SMS_Ios:PageRenderer { private readonly TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); OnElementChanged 保護オーバーライドボイド(VisualElementChangedEventArgs電子) {base.OnElementChanged(E); AppDelegate smsObj =新しいAppDelegate(); bool a = smsObj。ShowAndSendSMS(新しい文字列[] {"123"}、 "こんにちは"); } } } –