Advertisement
Guest User

Example

a guest
Dec 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. protected override async void OnResume()
  2.         {
  3.             //Helpers.Settings is James's Settings plugin, this setting with the replaces works in other parts so i have no reason
  4.             //to assume this is the cause
  5.             var req = new RegistrationUpdate()
  6.             {
  7.                 SerialKey = Helpers.Settings.License.Replace("/", "").Replace("\\", "").Replace('"', ' ').Trim()
  8.             };
  9.            
  10.             var stringc = new StringContent(JsonConvert.SerializeObject(req), Encoding.UTF8, "application/json");
  11.             //Just a manager that uses a httpclient to stick getKey behind our API's URL and make a post request with the stringcontent
  12.             //as the post body
  13.             var res = await RestManager.Instance.ExecuteRest("getKey", stringc);
  14.             //Null if the api is down or if there is an error on the api's side, manager reports this to another api call that saves
  15.             //the api response/ stacktrace, offline is when the user doesnt have connection.
  16.             if (res != null && res != "offline")
  17.             {
  18.                 //So here Res is Not NULL and Not Offline, so the null reference cant happen here.
  19.                 var resm = JsonConvert.DeserializeObject<RegistrationKey>(res);
  20.                 //Another check JIC also references crossfirebase but would be weird if this is the case.
  21.                 if (resm.RegToken == "" || resm.RegToken != CrossFirebasePushNotification.Current.Token)
  22.                 {
  23.                     //More of the same, create a request to send to the api
  24.                     var request = new RegistrationUpdate()
  25.                     {
  26.                         RegToken = CrossFirebasePushNotification.Current.Token,
  27.                         SerialKey = Helpers.Settings.License.Replace("/", "").Replace("\\", "").Replace('"', ' ').Trim()
  28.                     };
  29.                     try
  30.                     {
  31.                         //Stuck this in a try catch to see if this part was the cause, since it would just continue on and not crash.
  32.                         //But the crash still happens so this part isnt the cause
  33.                         var stringContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
  34.                         await RestManager.Instance.ExecuteRest("SetPushtoken", stringContent);
  35.                     }
  36.                     catch
  37.                     {
  38.  
  39.                     }
  40.                    
  41.                 }
  42.             }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement