Reputation: 19
I’m working on a .NET MAUI application for iOS where I’ve integrated Urban Airship for push notifications. According to the Urban Airship documentation, the TakeOff
method should be configured in the FinishedLaunching
method. Along with TakeOff
, we also have UAirship.Push.UserPushNotificationsEnabled = true;
which triggers the OS to ask for push notification permissions.
In our app, we have a different flow where we trigger the OS push notifications permission at a later stage. So initially, we don’t want UAirship.Push.UserPushNotificationsEnabled = true;
. However, unless we set this, we won’t receive push notifications from Urban Airship.
To work around this, I initiated TakeOff
during FinishedLaunching
and set UAirship.Push.UserPushNotificationsEnabled = true;
in didRegisterForRemoteNotificationsWithDeviceToken
. But this is causing the application to crash. There’s no stack trace generated, but while debugging, I found that the app crashes at the line where UAirship.Push.UserPushNotificationsEnabled = true;
.
Interestingly, if I place UAirship.Push.UserPushNotificationsEnabled = true;
immediately after TakeOff()
, the issue doesn’t occur. But our use case doesn’t allow for this.
Following is the code scenario for Crash.
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
//TakeOff is being performed
}
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
......
UAirship.Push.UserPushNotificationsEnabled = true;
.........
}
I have tried putting
UAirship.Push.UserPushNotificationsEnabled = true;
In different places, but unless it is placed immediately after TakeOff application is always crashing whenever it is coming into
UserPushNotificationsEnabled
line.
Upvotes: 0
Views: 98
Reputation: 980
I resolved this issue by placing this call in shared code. As well as using
Airship.Instance.UserNotificationsEnabled = true;
instead of
UAirship.Push.UserPushNotificationsEnabled = true;
hope this helps.
Upvotes: 0