sequenceDiagram
  participant C as client app
  participant A as agent
  participant S as SMP server
  participant N as NTF server
  participant APN as APN

  note over C, APN: register subscription

  alt register existing
    C -->> A: registerToken
  else create new connection
    A -->> S: create/joinConnection
    note over A, S: ...<br>Connection handshake<br>...
    S -->> A: CON
  end
  A ->> S: NKEY nKey
  S ->> A: NID nId
  A ->> N: SNEW tknId dhKey (smpServer, nId, nKey)
  N ->> A: ID subId dhKey
  N ->> S: NSUB nId
  S ->> N: OK / NMSG:<br>confirm subscription

  note over C, APN: notify about message

  S ->> N: NMSG
  N ->> APN: APNSMutableContent<br>ntfQueue, nonce
  APN ->> C: UNMutableNotificationContent
  note over C, S: ...<br>Client awaken, message is received<br>...
  S ->> C: message
  note over C: show notification

  note over C, APN: change APN token

  APN ->> C: new device token
  C -->> A: updateToken()
  A -->> N: TUPD tknId newDeviceToken
  note over C, N: ...<br>Verify token<br>...
