Skip to content

Instantly share code, notes, and snippets.

@astjohn
Created October 3, 2017 19:43
Show Gist options
  • Save astjohn/6492bec85af649e160a8c073b7fa2256 to your computer and use it in GitHub Desktop.
Save astjohn/6492bec85af649e160a8c073b7fa2256 to your computer and use it in GitHub Desktop.
push notification xamarin
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// do some stuff
// check if launched by push tap
if (launchOptions != null && launchOptions[UIApplication.LaunchOptionsRemoteNotificationKey] != null)
{
// re-using remote notification logic here for when app loads after user
// has interacted with remote notification from tray
this.DidReceiveRemoteNotification(application, launchOptions, (UIBackgroundFetchResult result) =>
{
// do nothing after handled by DidReceiveRemoteNotification
});
}
// etc....
}
// etc...
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, System.Action<UIBackgroundFetchResult> completionHandler)
{
base.DidReceiveRemoteNotification(application, userInfo, completionHandler);
var sitataCtrl = STASDKController.SharedInstance;
sitataCtrl.ReceivePushNotification(userInfo, completionHandler);
if (application.ApplicationState == UIApplicationState.Active)
{
// app is currently active, can update badges or visuals here
}
else if (application.ApplicationState == UIApplicationState.Background)
{
// app is in background
}
else if (application.ApplicationState == UIApplicationState.Inactive)
{
// app is transitioning from background to foreground (user taps notification)
// launch the screen for a particular push notification (when applicable)
sitataCtrl.LaunchPushNotificationScreen(userInfo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment