vapor / apns

Helpful extensions and abstractions for using APNSwift
MIT License
115 stars 29 forks source link

The operation could not be completed. (APNSCore.APNSError error 1.) #56

Closed metin-atalay closed 9 months ago

metin-atalay commented 9 months ago

The given error

The operation could not be completed. (APNSCore.APNSError error 1.)

Usage

I register users in my application and send push notifications. I often encounter the error mentioned in the title. For example, I have 30 users, and when looping through them within a 'for' loop, I encounter an error while sending an APNS push notification to the 25th user. I haven't been able to resolve it yet.

To Reproduce

    try await req.apns.client.sendAlertNotification(
                                        .init(
                                            alert: .init(
                                                title: .raw("Earthquake Alert"),
                                                subtitle: .raw("Magnitude \(quake.magnitude.fraction(minDigits: 1, maxDigits: 1))"),
                                                body: .raw("There is an earthquake occurring near \(quake.place). Depth \(quake.depth.fraction(minDigits: 1, maxDigits: 1)) km")
                                            ),
                                            expiration: .immediately,
                                            priority: .immediately,
                                            topic: "com.metinatalay.earthquake",
                                            payload: Payload(acme1: "", acme2: 2)
                                        ),
                                        deviceToken: "5d089ab68c40e5d5a5d16a0b01ce39cccff06040b6405f3a84ef45e73712a401"
                                    )

Expected behavior

Typically, one user is getting stuck; I am waiting for push notifications to be sent to all users

Environment

vzsg commented 9 months ago

Print the description of the error instead of the localizedDescription, it might reveal something useful.

metin-atalay commented 9 months ago

thank you for the reply, I will try and post it here.

metin-atalay commented 9 months ago

I see the bug but I am confused. I register these devices and type firebase. How does it give such an error? Thank you for the advice.

deviceID : 0fae0a2a71bd432b6c2db1ed8cd838392bab1a6a16addcab1d77baeca18c7468

▿ APNSError
  - responseStatus : 410
  ▿ apnsID : Optional<UUID>
    ▿ some : 9706DA1E-4A44-08A1-2FE6-753997CC5816
      - uuid : "9706DA1E-4A44-08A1-2FE6-753997CC5816"
  ▿ reason : Optional<ErrorReason>
    ▿ some : ErrorReason
      - _reason : APNSCore.APNSError.ErrorReason.Reason.unregistered
  ▿ timestamp : Optional<Date>
    ▿ some : 2024-01-20 08:05:45 +0000
      - timeIntervalSinceReferenceDate : 727430745.8180001
vzsg commented 9 months ago

That's a "normal" error result if the user has deleted or reinstalled the application. You should gracefully handle this error and not send messages to this APNS token in the future.

Although I don't understand what you mean by Firebase here, you don't seem to be using FCM?

metin-atalay commented 9 months ago

I'm not currently using FSM, it would be good to switch to it. Actually, I used to work at a bank where I kept track of customers and their registered Device IDs, sending specific pushes. I had tried to create a similar structure. But, as you suggested, using FSM would be better. Thanks for your support. Vapor and @vzsg 💚

kylebrowning commented 9 months ago

Personally don't think FCM is better. But I'm biased.