Exemplo n.º 1
0
    public void SetupGetSocial()
    {
        GetSocial.SetPushNotificationTokenListener(deviceToken => {
            _console.LogD(string.Format("DeviceToken: {0}", deviceToken), false);
        });
        GetSocial.SetNotificationListener((notification, wasClicked) => {
            // handle chat message
            if (notification.NotificationAction.Type.Equals("open_chat_message"))
            {
                _latestChatId = notification.NotificationAction.Data["open_messages_for_id"];
                if (GetSocial.IsInitialized)
                {
                    ShowChat();
                }
                return(true);
            }
            if (notification.NotificationAction.Type.Equals(GetSocialActionType.AddFriend))
            {
                ShowPopup(notification);
                return(true);
            }
            _console.LogD(string.Format("Notification(wasClicked : {0}): {1}", wasClicked, notification));
            if (!wasClicked)
            {
                return(false);
            }

            return(HandleAction(notification.NotificationAction));
        });

        // Set custom listener for global errors
        GetSocial.SetGlobalErrorListener(error => {
            _console.LogE("Global error listener invoked with message: " + error.Message);
        });

        _console.LogD("Setting up GetSocial...");
        _getSocialUnitySdkVersion            = GetSocial.UnitySdkVersion;
        _getSocialUnderlyingNativeSdkVersion = GetSocial.NativeSdkVersion;

        RegisterInvitePlugins();

        GetSocial.User.SetOnUserChangedListener(() => {
            _console.LogD("GetSocial is initialized and user is retrieved");
            GetSocial.User.IsPushNotificationsEnabled(isEnabled => ((SettingsSection)_menuSections.Find(section => section is SettingsSection)).PnEnabled = isEnabled, error => Debug.LogError("Failed to get PN status " + error));
            FetchCurrentUserData();
        });
    }