OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
625 stars 215 forks source link

[Bug]: Calling optIn() on iOS device is not re-enabling notifications #921

Closed daveshirman closed 4 months ago

daveshirman commented 4 months ago

What happened?

Trying to call OneSignal.User.pushSubscription.optIn(); on iOS device is sending this payload through Xcode console logs:

VERBOSE: HTTP Request (OneSignalUser.OSRequestUpdateSubscription) with URL: https://api.onesignal.com/apps/b9e69707-9150-41fb-874c-6f2a82846ba8/subscriptions/b466a12a-c5d4-4969-a324-0688f8e594c2, with parameters: {
  "subscription" : {
    "notification_types" : -13,
    "app_version" : "2.6.1",
    "sdk" : "050202",
    "device_os" : "17.5",
    "enabled" : false
  }
}

Which I am pretty sure should say "enabled": true

This means I can't register for push notifications on iOS

Note - on Android, it's fine.

Steps to reproduce?

1. Install latest package version 5.2.2
2. Follow setup guide for iOS
3. Call `OneSignal.User.pushSubscription.optIn()`
4. See `subscription` payload in Xcode console log showing enabled is `false`, not `true`.

What did you expect to happen?

I expected subscriptions to be enabled on iOS

OneSignal Flutter SDK version

5.2.2

Which platform(s) are affected?

Relevant log output

VERBOSE: HTTP Request (OneSignalUser.OSRequestUpdateSubscription) with URL: https://api.onesignal.com/apps/b9e69707-9150-41fb-874c-6f2a82846ba8/subscriptions/b466a12a-c5d4-4969-a324-0688f8e594c2, with parameters: {
  "subscription" : {
    "notification_types" : -13,
    "app_version" : "2.6.1",
    "sdk" : "050202",
    "device_os" : "17.5",
    "enabled" : false
  }
}
VERBOSE: network response (OneSignalUser.OSRequestUpdateSubscription) with URL https://api.onesignal.com/apps/b9e69707-9150-41fb-874c-6f2a82846ba8/subscriptions/b466a12a-c5d4-4969-a324-0688f8e594c2: {
    httpStatusCode = 200;
}

Code of Conduct

jkasten2 commented 4 months ago

@daveshirman notification_types = -13 means that your iOS bundle id doesn't have the push notification capabilities enabled.

Double check you have done the first part of the "2. iOS Setup" in the OneSignal Flutter setup guide:

Open the .xcworkspace file in Xcode located your project's ios folder. Select the root project > your main app target > Signing & Capabilities. If you do not see Push Notifications enabled, click + Capability and add Push Notifications. image

daveshirman commented 4 months ago

Thanks - this is correct. Weird as this was previously set up fine and I hadn't changed this setting. Cheers.

jkasten2 commented 4 months ago

@daveshirman If you change your bundle id then Apple treats it as a new app, and you will have to enable it for the new id.