Search Unity

How to redirect user when app is opened from notification

Discussion in 'iOS and tvOS' started by Ankit_JeGames, Dec 24, 2019.

  1. Ankit_JeGames

    Ankit_JeGames

    Joined:
    May 28, 2019
    Posts:
    11
    I don't know this is a normal thing or not to ask, but I require your guys help on this topic.

    In my app I want my user to tap on a notification and open a certain scene using the data of that FCM notification. I've already done this thing in Android but I'm unable to figure this out for iOS.

    Here is the code for my android notification redirection:

    Code (CSharp):
    1.  #if UNITY_ANDROID
    2.      if (hasFocus)
    3.      {
    4.          AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    5.          AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    6.          AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
    7.          string onClickScreen = intent.Call<string>("getStringExtra", "onClickScreen");
    8.          if (onClickScreen != null && onClickScreen.Trim().Length > 0)
    9.          {
    10.              redirectToAppropriateScreen(intent, onClickScreen);
    11.          }
    12.          intent.Call("removeExtra", "onClickScreen");
    13.      }
    14. #endif
     
  2. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Ankit_JeGames likes this.
  3. Ankit_JeGames

    Ankit_JeGames

    Joined:
    May 28, 2019
    Posts:
    11
    hey @kaarloew
    Thanks for the help. Sorry that I didn't thank you.

    But now I'm in a different problem NotificationServices works perfectly fine if the Application is running in background. but when the Application is closed and not running in the background, I get 0 as
    Code (csharp):
    1. remoteNotificationCount
    . please help.
     
  4. Blacklister001

    Blacklister001

    Joined:
    Jun 13, 2016
    Posts:
    11