0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

iOSシミュレータでpush通知は送れます

0
Last updated at Posted at 2026-07-07

以下翻訳

iOS 16以降を搭載し、macOS 13以降で動作するAppleシリコンまたはT2チップ搭載のMacにおいて、シミュレータがリモート通知をサポートするようになりました。シミュレータはApple Push Notification Service(APNS)のサンドボックス環境をサポートしています。サーバーからシミュレータ上で実行中のアプリにリモート通知を送信するには、APNSサンドボックス(api.sandbox.push.apple.com)に接続してください。各シミュレータは、そのシミュレータと実行環境であるMacハードウェアの組み合わせに基づいた固有の登録トークンを生成します。詳細については「User Notifications」を参照してください。
リモート通知は、.apnsペイロードファイルやsimctl pushコマンドを使用したローカルシミュレーションによる通知よりも多くの機能(Notification Service Extensionsなど)をサポートしています。
デバイス登録トークンの長さは可変です。シミュレータのトークンは、現在実機で使用されているトークンよりも長くなる可能性があります。トークンの長さや形式を固定値としてハードコードしないでください。

つまり最近のMacを使用していれば実際のトークンが取得でき通知を送ることができる。
xcrun simctl push を使う必要がない。

image.png

import { initializeApp } from "firebase-admin";
import { getMessaging } from "firebase-admin/messaging";

const app = initializeApp();
async function sendPushToToken(
  token: string,
  title: string,
  body: string
): Promise<string> {
  return getMessaging(app).send({
    token,
    notification: { title, body },
  });
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?