4

フォアグラウンド時通知でUIAlertControllerを出す処理は、なんとか出来たのですが
バックグラウンド時に

- [⚪︎⚪︎ presentViewController:alertController animated:YES completion:nil];

の⚪︎⚪︎の部分をどう書けば良いかがわかりません。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    // アプリ起動中(フォアグラウンド)に通知が届いた場合
    if(application.applicationState == UIApplicationStateActive) {
        // ここに処理を書く
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:notification.alertBody message:notification.alertAction preferredStyle:UIAlertControllerStyleAlert];

        // addActionした順に左から右にボタンが配置されます
        [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            // otherボタンが押された時の処理
        }]];
        UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
        while(topController.presentedViewController) {
            topController = topController.presentedViewController;
        }

        // アラート表示処理
        [topController presentViewController:alertController animated:YES completion:nil];
    }

    // アプリがバックグラウンドにある状態で通知が届いた場合
    if(application.applicationState == UIApplicationStateInactive) {
        // ここに処理を書く
        //バックグラウンド時のalertControllerでの表示がわからない。
    }

    // 通知領域から削除する
    [[UIApplication sharedApplication] cancelLocalNotification:notification];
}

どう書けばよいのでしょうか?

2
  • アプリケーションがバックグラウンドにある状態ではUIの更新はできません。しかし、通知なら自動的に通知の内容でアラートビューと同じものがシステムによって表示されると思いますが、それではダメなのですか? 2015年8月27日 16:51
  • @ kishikawa katsumi "システムの通知の種類は設定に依存する"という情報を知らずになんとかしようとしていました。 デフォルトのアラートスタイルをダイアログボックスにしたくていろいろ調べてみましたが、調べてみた範囲では不可能のようです。 残念です。 ありがとうございました。 2015年8月29日 14:41

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。