AppDelegate.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Foundation;
  5. using UIKit;
  6. using Xamarin.Auth;
  7. using XamarinFormsGoogleDriveAPI.iOS.Renderer;
  8. namespace XamarinFormsGoogleDriveAPI.iOS
  9. {
  10. // The UIApplicationDelegate for the application. This class is responsible for launching the
  11. // User Interface of the application, as well as listening (and optionally responding) to
  12. // application events from iOS.
  13. [Register("AppDelegate")]
  14. public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
  15. {
  16. //
  17. // This method is invoked when the application has loaded and is ready to run. In this
  18. // method you should instantiate the window, load the UI into it and then make the window
  19. // visible.
  20. //
  21. // You have 17 seconds to return from this method, or iOS will terminate your application.
  22. //
  23. public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  24. {
  25. string userAgent =
  26. "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36";
  27. // set default useragent
  28. NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject(userAgent),
  29. NSObject.FromObject("UserAgent"));
  30. NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionary);
  31. var userDefaults = NSUserDefaults.StandardUserDefaults.StringForKey("FirstRun");
  32. if (string.IsNullOrEmpty(userDefaults))
  33. {
  34. var account = AccountStore.Create().FindAccountsForService("Google").FirstOrDefault();
  35. if (account != null)
  36. AccountStore.Create().Delete(account, "Google");
  37. NSUserDefaults.StandardUserDefaults.SetString("Yes", "FirstRun");
  38. }
  39. global::Xamarin.Forms.Forms.Init();
  40. CustomFabRenderer.Init();
  41. LoadApplication(new App());
  42. return base.FinishedLaunching(app, options);
  43. }
  44. }
  45. }