2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using XLabs.Ioc.Unity;
|
|
|
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Services;
|
|
|
|
|
using Microsoft.Practices.Unity;
|
|
|
|
|
using Bit.iOS.Services;
|
2016-05-03 00:50:16 +03:00
|
|
|
|
using Plugin.Settings;
|
2016-05-03 09:08:50 +03:00
|
|
|
|
using Plugin.Connectivity;
|
|
|
|
|
using Acr.UserDialogs;
|
2016-05-06 07:17:38 +03:00
|
|
|
|
using Bit.App.Repositories;
|
2016-05-21 19:32:34 +03:00
|
|
|
|
using Plugin.Fingerprint;
|
|
|
|
|
using Plugin.Fingerprint.Abstractions;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Xamarin.Forms;
|
2016-05-22 05:50:15 +03:00
|
|
|
|
using Bit.App;
|
2016-05-28 23:06:53 +03:00
|
|
|
|
using Bit.iOS.Core.Services;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS
|
|
|
|
|
{
|
|
|
|
|
// The UIApplicationDelegate for the application. This class is responsible for launching the
|
|
|
|
|
// User Interface of the application, as well as listening (and optionally responding) to
|
|
|
|
|
// application events from iOS.
|
|
|
|
|
[Register("AppDelegate")]
|
|
|
|
|
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// This method is invoked when the application has loaded and is ready to run. In this
|
|
|
|
|
// method you should instantiate the window, load the UI into it and then make the window
|
|
|
|
|
// visible.
|
|
|
|
|
//
|
|
|
|
|
// You have 17 seconds to return from this method, or iOS will terminate your application.
|
|
|
|
|
//
|
|
|
|
|
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
|
|
|
|
|
{
|
2016-05-21 19:32:34 +03:00
|
|
|
|
CrossFingerprint.AllowReuse = false;
|
|
|
|
|
|
2016-05-02 09:52:09 +03:00
|
|
|
|
global::Xamarin.Forms.Forms.Init();
|
|
|
|
|
|
|
|
|
|
if(!Resolver.IsSet)
|
|
|
|
|
{
|
|
|
|
|
SetIoc();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 06:26:35 +03:00
|
|
|
|
LoadApplication(new App.App(
|
2016-05-21 19:32:34 +03:00
|
|
|
|
Resolver.Resolve<IAuthService>(),
|
|
|
|
|
Resolver.Resolve<IDatabaseService>(),
|
|
|
|
|
Resolver.Resolve<IFingerprint>(),
|
2016-05-22 06:26:35 +03:00
|
|
|
|
Resolver.Resolve<ISettings>()));
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-06-14 07:19:18 +03:00
|
|
|
|
UINavigationBar.Appearance.ShadowImage = new UIImage();
|
|
|
|
|
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
|
|
|
|
|
|
2016-05-02 09:52:09 +03:00
|
|
|
|
return base.FinishedLaunching(app, options);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-21 19:32:34 +03:00
|
|
|
|
public override void DidEnterBackground(UIApplication uiApplication)
|
|
|
|
|
{
|
2016-06-11 09:43:53 +03:00
|
|
|
|
var view = new UIView(UIApplication.SharedApplication.KeyWindow.Frame)
|
2016-05-21 19:32:34 +03:00
|
|
|
|
{
|
|
|
|
|
Tag = 4321
|
|
|
|
|
};
|
2016-06-11 09:43:53 +03:00
|
|
|
|
|
|
|
|
|
var backgroundView = new UIView(UIApplication.SharedApplication.KeyWindow.Frame)
|
|
|
|
|
{
|
|
|
|
|
BackgroundColor = UIColor.FromPatternImage(new UIImage("bg.png"))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var imageView = new UIImageView(new UIImage("logo.png"))
|
|
|
|
|
{
|
|
|
|
|
Center = view.Center
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
view.AddSubview(backgroundView);
|
|
|
|
|
view.AddSubview(imageView);
|
|
|
|
|
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.AddSubview(view);
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.BringSubviewToFront(view);
|
|
|
|
|
UIApplication.SharedApplication.KeyWindow.EndEditing(true);
|
2016-05-22 05:50:15 +03:00
|
|
|
|
|
|
|
|
|
// Log the date/time we last backgrounded
|
|
|
|
|
CrossSettings.Current.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
|
2016-05-21 19:32:34 +03:00
|
|
|
|
|
|
|
|
|
base.DidEnterBackground(uiApplication);
|
|
|
|
|
Debug.WriteLine("DidEnterBackground");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnResignActivation(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
base.OnResignActivation(uiApplication);
|
|
|
|
|
Debug.WriteLine("OnResignActivation");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WillTerminate(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
base.WillTerminate(uiApplication);
|
|
|
|
|
Debug.WriteLine("WillTerminate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnActivated(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
base.OnActivated(uiApplication);
|
|
|
|
|
Debug.WriteLine("OnActivated");
|
|
|
|
|
|
|
|
|
|
var view = UIApplication.SharedApplication.KeyWindow.ViewWithTag(4321);
|
|
|
|
|
if(view != null)
|
|
|
|
|
{
|
|
|
|
|
view.RemoveFromSuperview();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WillEnterForeground(UIApplication uiApplication)
|
|
|
|
|
{
|
|
|
|
|
SendLockMessage();
|
|
|
|
|
base.WillEnterForeground(uiApplication);
|
|
|
|
|
Debug.WriteLine("WillEnterForeground");
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 10:08:12 +03:00
|
|
|
|
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-21 19:32:34 +03:00
|
|
|
|
private void SendLockMessage()
|
|
|
|
|
{
|
2016-05-22 06:26:35 +03:00
|
|
|
|
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Lock", false);
|
2016-05-21 19:32:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 09:52:09 +03:00
|
|
|
|
private void SetIoc()
|
|
|
|
|
{
|
|
|
|
|
var container = new UnityContainer();
|
|
|
|
|
|
|
|
|
|
container
|
2016-05-06 07:17:38 +03:00
|
|
|
|
// Services
|
2016-05-02 09:52:09 +03:00
|
|
|
|
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
|
2016-05-06 07:17:38 +03:00
|
|
|
|
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
|
2016-05-02 09:52:09 +03:00
|
|
|
|
.RegisterType<ISecureStorageService, KeyChainStorageService>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
|
2016-05-03 09:08:50 +03:00
|
|
|
|
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
2016-05-06 07:17:38 +03:00
|
|
|
|
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
2016-05-07 05:29:03 +03:00
|
|
|
|
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
2016-05-06 07:17:38 +03:00
|
|
|
|
// Repositories
|
|
|
|
|
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<ISiteRepository, SiteRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
|
// Other
|
|
|
|
|
.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
|
2016-05-03 09:08:50 +03:00
|
|
|
|
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
|
2016-05-21 19:32:34 +03:00
|
|
|
|
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
|
|
|
|
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
|
|
|
|
Resolver.SetResolver(new UnityResolver(container));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|