public async void UpdateDeviceInfo()
 {
     if (userdataindb != null)
     {
         var deviceRequestmodel = new UpdateDeviceInfoModel()
         {
             device_id = Device.RuntimePlatform == Device.Android ? 1 : Device.RuntimePlatform == Device.iOS ? 2 : 0,
             user_id = userdataindb.user_id,
             device_token = Application.Current.Properties.ContainsKey("AppFirebaseToken") ? Application.Current.Properties["AppFirebaseToken"].ToString() : null
         };
         UpdateDeviceInfoResponse deviceInfoResponse;
         try
         {
             deviceInfoResponse = await _webApiRestClient.PostAsync<UpdateDeviceInfoModel, UpdateDeviceInfoResponse>(ApiUrl.UpdateDeviceInfo, deviceRequestmodel);
         }
         catch (Exception ex)
         {
             deviceInfoResponse = null;
         }
         if (deviceInfoResponse != null)
         {
             //if (deviceInfoResponse.status)
             //{
             //    //await MaterialDialog.Instance.SnackbarAsync(message: deviceInfoResponse.message, msDuration: 3000);
             //}
             //else
             //{
             //    await MaterialDialog.Instance.SnackbarAsync(message: deviceInfoResponse.message, msDuration: 3000);
             //}
         } 
     }
 }
Beispiel #2
0
        //public static void UpdateFirebaseService(UserData userData = null)
        //{
        //    if (Device.RuntimePlatform == Device.Android)
        //    {

        //        CrossFirebasePushNotification.Current.RegisterForPushNotifications();

        //        CrossFirebasePushNotification.Current.Subscribe("general");
        //        CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
        //        {
        //            System.Diagnostics.Debug.WriteLine($"TOKEN REC: {p.Token}");
        //            FirebaseToken = p.Token;

        //            if (userData != null)
        //            {
        //                UpdateDeviceInfo(userData);
        //            }

        //        };
        //        System.Diagnostics.Debug.WriteLine($"TOKEN: {CrossFirebasePushNotification.Current.Token}");

        //        CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
        //        {
        //            try
        //            {
        //                System.Diagnostics.Debug.WriteLine("Received");
        //                if (p.Data.ContainsKey("body"))
        //                {
        //                    Device.BeginInvokeOnMainThread(() =>
        //                    {
        //                        var data = $"{p.Data["body"]}";
        //                    });

        //                }
        //            }
        //            catch (Exception ex)
        //            {

        //            }

        //        };

        //        CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
        //        {
        //            //System.Diagnostics.Debug.WriteLine(p.Identifier);

        //            System.Diagnostics.Debug.WriteLine("Opened");
        //            foreach (var data in p.Data)
        //            {
        //                System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
        //            }

        //            if (!string.IsNullOrEmpty(p.Identifier))
        //            {
        //                Device.BeginInvokeOnMainThread(() =>
        //                {
        //                    var data = p.Identifier;
        //                });
        //            }
        //            else if (p.Data.ContainsKey("color"))
        //            {
        //                Device.BeginInvokeOnMainThread(() =>
        //                {
        //                    //mPage.Navigation.PushAsync(new ContentPage()
        //                    //{
        //                    //    BackgroundColor = Color.FromHex($"{p.Data["color"]}")

        //                    //});
        //                });

        //            }
        //            else if (p.Data.ContainsKey("aps.alert.title"))
        //            {
        //                Device.BeginInvokeOnMainThread(() =>
        //                {
        //                    var data = $"{p.Data["aps.alert.title"]}";
        //                });

        //            }
        //        };

        //        CrossFirebasePushNotification.Current.OnNotificationAction += (s, p) =>
        //        {
        //            System.Diagnostics.Debug.WriteLine("Action");

        //            if (!string.IsNullOrEmpty(p.Identifier))
        //            {
        //                System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
        //                foreach (var data in p.Data)
        //                {
        //                    System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
        //                }

        //            }

        //        };

        //        CrossFirebasePushNotification.Current.OnNotificationDeleted += (s, p) =>
        //        {
        //            System.Diagnostics.Debug.WriteLine("Dismissed");
        //        };
        //    }
        //}

        private async void UpdateDeviceInfo()
        {
            var deviceRequestmodel = new UpdateDeviceInfoModel()
            {
                DeviceId    = Device.RuntimePlatform == Device.Android ? 1 : Device.RuntimePlatform == Device.iOS ? 2 : 0,
                UserId      = userData.UserId,
                DeviceToken = Application.Current.Properties.ContainsKey("AppFirebaseToken") ? Application.Current.Properties["AppFirebaseToken"].ToString() : null
            };
            UpdateDeviceInfoResponse deviceInfoResponse;

            try
            {
                deviceInfoResponse = await webApiRestClient.PostAsync <UpdateDeviceInfoModel, UpdateDeviceInfoResponse>(ApiHelpers.UpdateDeviceInfo, deviceRequestmodel);
            }
            catch (Exception ex)
            {
                Console.WriteLine("UpdateDeviceApi_Exception:-->" + ex.Message);
                deviceInfoResponse = null;
            }
            if (deviceInfoResponse != null)
            {
                if (deviceInfoResponse.status)
                {
                    await MaterialDialog.Instance.SnackbarAsync(message : AppResource.DeviceInfoupdated,
                                                                msDuration : MaterialSnackbar.DurationShort);
                }
                else
                {
                    await MaterialDialog.Instance.SnackbarAsync(message : deviceInfoResponse.message,
                                                                msDuration : MaterialSnackbar.DurationShort);
                }
            }
            else
            {
                await MaterialDialog.Instance.SnackbarAsync(message : AppResource.ExceptionDeviceInfo,
                                                            msDuration : MaterialSnackbar.DurationShort);
            }
        }