App Center のクラッシュ (tvOS)

重要

Visual Studio App Center は、2025 年 3 月 31 日に廃止される予定です。 完全に廃止されるまで Visual Studio App Center を引き続き使用できますが、移行を検討できる推奨される代替手段がいくつかあります。

サポートタイムラインと代替手段の詳細については、こちらを参照してください。

App Center のクラッシュでは、アプリがクラッシュするたびにクラッシュ ログが自動的に生成されます。 ログは最初にデバイスのストレージに書き込まれ、ユーザーがアプリを再度起動すると、クラッシュ レポートが App Center に送信されます。 クラッシュの収集は、ベータ版アプリとライブ アプリの両方 (つまり、App Storeに送信されたもの) に対して機能します。 クラッシュ ログには、クラッシュの修正に役立つ重要な情報が含まれています。

アプリケーションで SDK をまだ設定していない場合は、はじめにセクションに従います。

また、tvOS 上のクラッシュ ログにはシンボリック化が必要です。アプリのシンボルを提供する方法について説明している App Center Diagnostics ドキュメントをチェックします。

注意

適切にシンボリック化されたスタック トレースを受信するには、ビットコードが無効になっていることを確認します。 ビットコードの詳細については、App Center の iOS シンボリック化に関するドキュメントを参照してください

注意

App Center の 4.0.0 バージョンでは、破壊的変更が導入されました。 App Center SDK 4.0.0 以降への移行に関するセクションに従って、App Center を以前のバージョンから移行します。

テスト クラッシュを生成する

App Center のクラッシュには、SDK を簡単にテストするためのテスト クラッシュを生成する API が用意されています。 この API はテスト/ベータ アプリでのみ使用でき、運用アプリでは何も行いません。

[MSACCrashes generateTestCrash];
Crashes.generateTestCrash()

以前のクラッシュに関する詳細情報を取得する

App Center のクラッシュには、アプリがクラッシュした場合に備えて詳細情報を提供する 2 つの API があります。

アプリは前のセッションでメモリ不足の警告を受け取りましたか?

SDK を開始した後は、いつでも、アプリが前のセッションでメモリ警告を受信したかどうかをチェックできます。

[MSACCrashes hasReceivedMemoryWarningInLastSession];
Crashes.hasReceivedMemoryWarningInLastSession

注意

このメソッドは、開始後Crashesにのみ使用する必要があり、常に または false 開始前に を返NOします。

注意

場合によっては、メモリが不足しているデバイスでイベントを送信できない場合があります。

前のセッションでアプリがクラッシュしましたか?

SDK を起動した後は、いつでも、前の起動でアプリがクラッシュした場合にチェックできます。

[MSACCrashes hasCrashedInLastSession];
Crashes.hasCrashedInLastSession

これは、クラッシュが発生した後にアプリの動作または UI を調整する場合に便利です。

注意

このメソッドは、開始後MSACCrashesにのみ使用する必要があり、常に または false 開始前に を返NOします。

前回のクラッシュの詳細

アプリが以前にクラッシュした場合は、最後のクラッシュに関する詳細を取得できます。

MSACErrorReport *crashReport = [MSACCrashes lastSessionCrashReport];
var crashReport = Crashes.lastSessionCrashReport

注意

このメソッドは、開始後 Crashes にのみ使用する必要があります。常に開始前にが返 nil されます。

この API には多数のユース ケースがあります。最も一般的なのは、この API を呼び出し、カスタム の CrashesDelegate を実装するユーザーです。

App Center のクラッシュの使用をカスタマイズする

App Center のクラッシュは、クラッシュ ログを App Center に送信する前と送信する際に、開発者が追加のアクションを実行するためのコールバックを提供します。

カスタム動作を追加するには、-protocol を CrashesDelegate採用する必要があります。そのメソッドはすべて省略可能です。

代理人として登録する

[MSACCrashes setDelegate:self];
Crashes.delegate = self

注意

App Center が起動直後 クラッシュする処理を開始するため、 を呼び出す AppCenter.start前にデリゲートを設定する必要があります。

クラッシュを処理する必要がありますか?

特定のクラッシュを crashes:shouldProcessErrorReport:処理する必要があるかどうかを判断する場合は、-protocol を採用 CrashesDelegateする クラスに -method を実装します。 たとえば、無視するシステム レベルのクラッシュがあり、App Center に送信したくない場合があります。

- (BOOL)crashes:(MSACCrashes *)crashes shouldProcessErrorReport:(MSACErrorReport *)errorReport {
  return YES; // return YES if the crash report should be processed, otherwise NO.
}
func crashes(_ crashes: Crashes, shouldProcess errorReport: ErrorReport) -> Bool {
  return true; // return true if the crash report should be processed, otherwise false.
}

処理されたエラー

App Center では、メソッドを使用して処理された例外を使用してエラーを trackError 追跡することもできます。 アプリでは、必要に応じて、処理されたエラー レポートにプロパティや添付ファイルを添付して、さらにコンテキストを提供できます。

@try {
  // Throw error.
} @catch (NSError *error) {

  // Init attachments.
  NSArray<MSACErrorAttachmentLog *> attachments = @[ MSACErrorAttachmentLog attachmentWithText:@"Hello world!" filename:@"hello.txt"] ]

  // Init properties.
  NSDictionary *properties = @{ "Category" : "Music", "Wifi" : "On" };

  // Track errors.
  [MSACCrashes trackError:error withProperties:properties attachments:attachments];
  [MSACCrashes trackError:error withProperties:properties attachments:nil];
  [MSACCrashes trackError:error withProperties:nil attachments:attachments];
  [MSACCrashes trackError:error withProperties:nil attachments:nil];
}
do {
  // Throw error.
} catch {

  // Init attachments.
  let attachments = [ErrorAttachmentLog.attachment(withText: "Hello world!", filename: "hello.txt")]

  // Init properties.
  let properties:Dictionary<String, String> = ["Category" : "Music", "Wifi" : "On"]

  // Track errors.
  Crashes.trackError(error, properties: properties, attachments: attachments)
  Crashes.trackError(error, properties: properties, attachments: nil)
  Crashes.trackError(error, properties: nil, attachments: attachments)
  Crashes.trackError(error, properties: nil, attachments: nil)
}

例外を追跡する場合は、 メソッドを使用 trackException できます。

@try {
  // Throw exceptions.
} @catch (NSException *exception) {

  // Init exceptions.
  MSACExceptionModel *customException1 = [MSACExceptionModel initWithType:@"Custom exception" exceptionMessage:"Track custom exception.", stackTrace:exception.callStackSymbols];
  MSACExceptionModel *customException2 = [MSACExceptionModel initWithException:exception];

  // Track exceptions.
  [MSACCrashes trackException:customException1 withProperties:properties attachments:nil];
  [MSACCrashes trackException:customException2 withProperties:properties attachments:nil];
}
do {
  // Throw exception.
} catch {

  // Init exception.
  let exception = ExceptionModel(withType: "Custom exception", exceptionMessage: "Track custom exception.", stackTrace: Thread.callStackSymbols)

  // Track exception.
  Crashes.trackException(exception, properties: properties, attachments: nil)
}

ユーザーのプライバシーが重要な場合は、クラッシュ レポートを App Center に送信する前に、ユーザーの確認を取得できます。 SDK は、クラッシュ レポートを送信する前にユーザーの確認を待つよう App Center のクラッシュに指示するコールバックを公開します。

これを行うことを選択した場合は、ユーザーの確認を取得する必要があります。たとえば、ダイアログ プロンプトで次のいずれかのオプションを使用します。 常に送信送信、送信 しない。 入力に基づいて、App Center のクラッシュに何をすべきかを伝え、クラッシュはそれに応じて処理されます。

注意

SDK ではこれに対するダイアログが表示されません。アプリは、ユーザーの同意を求めるために独自の UI を提供する必要があります。

注意

ユーザー確認ダイアログが実装されていない場合、アプリは明示的に を呼び出 notifyWithUserConfirmation すべきではありません。クラッシュ モジュールは、ログの送信を暗黙的に処理します。

次のメソッドは、ユーザー確認ハンドラーを設定する方法を示しています。

[MSACCrashes setUserConfirmationHandler:(^(NSArray<MSACErrorReport *> *errorReports) {

  // Your code to present your UI to the user, e.g. an UIAlertController.
  UIAlertController *alertController = [UIAlertController
      alertControllerWithTitle:@"Sorry about that!"
                      message:@"Do you want to send an anonymous crash report so we can fix the issue?"
                preferredStyle:UIAlertControllerStyleAlert];

  [alertController
      addAction:[UIAlertAction actionWithTitle:@"Don't send"
                                        style:UIAlertActionStyleCancel
                                      handler:^(UIAlertAction *action) {
                                        [MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationDontSend];
                                      }]];

  [alertController
      addAction:[UIAlertAction actionWithTitle:@"Send"
                                        style:UIAlertActionStyleDefault
                                      handler:^(UIAlertAction *action) {
                                        [MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationSend];
                                      }]];

  [alertController
      addAction:[UIAlertAction actionWithTitle:@"Always send"
                                        style:UIAlertActionStyleDefault
                                      handler:^(UIAlertAction *action) {
                                        [MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationAlways];
                                      }]];
  // Show the alert controller.
  [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
  return YES; // Return YES if the SDK should await user confirmation, otherwise NO.
})];
MSACCrashes.setUserConfirmationHandler({ (errorReports: [MSACErrorReport]) in

  // Your code to present your UI to the user, e.g. an UIAlertController.
  let alertController = UIAlertController(title: "Sorry about that!",
                                          message: "Do you want to send an anonymous crash report so we can fix the issue?",
                                          preferredStyle:.alert)

  alertController.addAction(UIAlertAction(title: "Don't send", style: .cancel) {_ in
    MSACCrashes.notify(with: .dontSend)
  })

  alertController.addAction(UIAlertAction(title: "Send", style: .default) {_ in
    MSACCrashes.notify(with: .send)
  })

  alertController.addAction(UIAlertAction(title: "Always send", style: .default) {_ in
    MSACCrashes.notify(with: .always)
  })

  // Show the alert controller.
  self.window?.rootViewController?.present(alertController, animated: true)
  return true // Return true if the SDK should await user confirmation, otherwise return false.
})

上記のハンドラー ブロックで を返した YES/true 場合、アプリはユーザーのアクセス許可を取得し、次の API を使用して結果を SDK にメッセージする必要があります。 上記のサンプルのように、これに対してアラートを使用している場合は、-callback の alertView:clickedButtonAtIndex:実装内から呼び出します。

// Depending on the users's choice, call notifyWithUserConfirmation: with the right value.
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationDontSend];
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationSend];
[MSACCrashes notifyWithUserConfirmation:MSACUserConfirmationAlways];
// Depending on the user's choice, call notify(with:) with the right value.
MSACCrashes.notify(with: .dontSend)
MSACCrashes.notify(with: .send)
MSACCrashes.notify(with: .always)

クラッシュ ログの送信状態に関する情報を取得する

場合によっては、アプリのクラッシュの状態を知りたい場合があります。 一般的なユース ケースは、アプリがクラッシュ レポートを送信していることをユーザーに伝える UI を表示する場合や、起動後にアプリが迅速にクラッシュする場合は、クラッシュ ログを送信できるようにアプリの動作を調整する必要がある場合です。 -protocol では CrashesDelegate、アプリで使用して何が起こっているかを通知するために使用できる 3 つの異なるコールバックが定義されています。

SDK がクラッシュ ログを送信する前に、次のコールバックが呼び出されます

- (void)crashes:(MSACCrashes *)crashes willSendErrorReport:(MSACErrorReport *)errorReport {
  // Your code, e.g. to present a custom UI.
}
func crashes(_ crashes: Crashes, willSend errorReport: ErrorReport) {
  // Your code, e.g. to present a custom UI.
}

エンドポイントでネットワークの問題や停止が発生し、アプリを再起動した場合は、 willSendErrorReport プロセスの再起動後に再度トリガーされます。

SDK がクラッシュ ログを正常に送信した後、次のコールバックが呼び出されます

- (void)crashes:(MSACCrashes *)crashes didSucceedSendingErrorReport:(MSACErrorReport *)errorReport {
  // Your code, e.g. to hide the custom UI.
}
func crashes(_ crashes: Crashes, didSucceedSending errorReport: ErrorReport) {
  // Your code goes here.
}

SDK がクラッシュ ログを送信できなかった場合は、次のコールバックが呼び出されます

- (void)crashes:(MSACCrashes *)crashes didFailSendingErrorReport:(MSACErrorReport *)errorReport withError:(NSError *)error {
  // Your code goes here.
}
func crashes(_ crashes: Crashes, didFailSending errorReport: ErrorReport, withError error: Error) {
  // Your code goes here.
}

受信は didFailSendingErrorReport4xx コードなどの回復不可能なエラーが発生した場合を意味します。 たとえば、 401 は が appSecret 間違っていることを意味します。

このコールバックは、ネットワークの問題である場合はトリガーされません。 この場合、SDK は再試行を続けます (また、ネットワーク接続がダウンしている間も再試行を一時停止します)。

クラッシュ レポートに添付ファイルを追加する

クラッシュ レポートにバイナリ添付ファイルとテキスト添付ファイルを追加できます。 SDK によってクラッシュと共に送信され、App Center ポータルで表示されます。 次のコールバックは、以前のアプリケーションの起動から格納されたクラッシュを送信する直前に呼び出されます。 クラッシュが発生しても呼び出されません。 テキストと画像をクラッシュに添付する方法の例を次に示します。

- (NSArray<MSACErrorAttachmentLog *> *)attachmentsWithCrashes:(MSACCrashes *)crashes
                                             forErrorReport:(MSACErrorReport *)errorReport {
  MSACErrorAttachmentLog *attachment1 = [MSACErrorAttachmentLog attachmentWithText:@"Hello world!" filename:@"hello.txt"];
  MSACErrorAttachmentLog *attachment2 = [MSACErrorAttachmentLog attachmentWithBinary:[@"Fake image" dataUsingEncoding:NSUTF8StringEncoding] filename:@"fake_image.jpeg" contentType:@"image/jpeg"];
  return @[ attachment1, attachment2 ];
}
func attachments(with crashes: Crashes, for errorReport: ErrorReport) -> [ErrorAttachmentLog]? {
  let attachment1 = ErrorAttachmentLog.attachment(withText: "Hello world!", filename: "hello.txt")
  let attachment2 = ErrorAttachmentLog.attachment(withBinary: "Fake image".data(using: String.Encoding.utf8), filename: nil, contentType: "image/jpeg")
  return [attachment1!, attachment2!]
}

注意

サイズ制限は現在 7 MB です。 大きな添付ファイルを送信しようとすると、エラーが発生します。

実行時に App Center のクラッシュを有効または無効にする

実行時に App Center のクラッシュを有効または無効にすることができます。 無効にした場合、SDK はアプリのクラッシュ レポートを実行しません。

[MSACCrashes setEnabled:NO];
Crashes.enabled = false

App Center のクラッシュを再度有効にするには、同じ API を使用しますが、 パラメーターとして を渡 YES/true します。

[MSACCrashes setEnabled:YES];
Crashes.enabled = true

状態は、アプリケーションの起動間でデバイスのストレージに保持されます。

注意

このメソッドは、開始後 Crashes にのみ使用する必要があります。

App Center のクラッシュが有効になっているかどうかを確認する

App Center のクラッシュが有効になっているかどうかをチェックすることもできます。

BOOL enabled = [MSACCrashes isEnabled];
var enabled = Crashes.enabled

注意

このメソッドは、開始後 Crashes にのみ使用する必要があり、常に開始前に戻ります false