LoginSignup
13
14

More than 5 years have passed since last update.

開発中のiOSアプリにMacからプッシュ通知を送る

Posted at

tl;dr

Pusher という macOSアプリで簡単に送ることができた

osx1.png

インストール

$ brew cask install pusher

以上

APNS証明書のインストール

これはいつもの作業だと思うので、以下の記事などを参考に。

プッシュ通知に必要な証明書の作り方2018

APNS証明書を自身のマシンにインストールできれば自動的にリスト表示してくれる

p12s.png

device token の取得

プッシュ通知の送り先を決めるために device token を指定する必要がある。
アプリにプッシュ通知を受けるための実装全般については 別の記事 を参考に。

プッシュ通知を受ける実装が完了していれば、通知を許可したタイミングで以下のデリゲートメソッドが呼ばれる。
取得した文字列をテキストボックスにコピーする。

AppDelegate.swift

// MARK: - UIApplicationDelegate

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
        print(token) // この文字列を device token としてテキストボックスに貼り付ける
    }

devicetoken.png

通知

Push ボタンを押すと通知がとぶ。

IMG_E918237FD2AC-1.png

13
14
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
13
14