mirror of
https://github.com/bitwarden/android.git
synced 2024-12-19 07:41:52 +03:00
Setup push notifications for android and ios
This commit is contained in:
parent
244936534e
commit
8677e9e7ae
13 changed files with 3262 additions and 2752 deletions
|
@ -36,7 +36,7 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
|
||||
<AndroidLinkMode>None</AndroidLinkMode>
|
||||
<AndroidLinkSkip />
|
||||
<AndroidLinkSkip>Xamarin.GooglePlayServices.Gcm;</AndroidLinkSkip>
|
||||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
||||
<BundleAssemblies>False</BundleAssemblies>
|
||||
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
|
||||
|
@ -46,6 +46,7 @@
|
|||
<MandroidI18n />
|
||||
<Debugger>Xamarin</Debugger>
|
||||
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
|
||||
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -118,6 +119,10 @@
|
|||
<HintPath>..\..\packages\Xam.Plugin.Connectivity.2.1.2\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.CurrentActivity, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Fingerprint, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Plugin.Fingerprint.1.1.1-beta\lib\MonoAndroid\Plugin.Fingerprint.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -134,6 +139,14 @@
|
|||
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\MonoAndroid10\Plugin.Settings.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\MonoAndroid10\PushNotification.Plugin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\MonoAndroid10\PushNotification.Plugin.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Splat.1.6.2\lib\monoandroid\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -194,6 +207,14 @@
|
|||
<HintPath>..\..\packages\Xamarin.Forms.2.2.0.31\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.GooglePlayServices.Base, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.GooglePlayServices.Base.25.0.0.0\lib\MonoAndroid41\Xamarin.GooglePlayServices.Base.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.GooglePlayServices.Gcm, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.GooglePlayServices.Gcm.25.0.0.0\lib\MonoAndroid41\Xamarin.GooglePlayServices.Gcm.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="XLabs.Ioc, Version=2.0.5782.12218, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\XLabs.IoC.2.0.5782\lib\portable-net45+netcore45+wp8+MonoAndroid1+MonoTouch1\XLabs.Ioc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -212,6 +233,7 @@
|
|||
<Compile Include="Controls\ExtendedTextCellRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedPickerRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
||||
<Compile Include="MainApplication.cs" />
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
<Compile Include="Services\ClipboardService.cs" />
|
||||
<Compile Include="Services\KeyStoreStorageService.cs" />
|
||||
|
|
|
@ -6,17 +6,8 @@ using Android.Runtime;
|
|||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.OS;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Services;
|
||||
using XLabs.Ioc.Unity;
|
||||
using XLabs.Ioc;
|
||||
using Bit.Android.Services;
|
||||
using Plugin.Settings;
|
||||
using Plugin.Connectivity;
|
||||
using Acr.UserDialogs;
|
||||
using Bit.App.Repositories;
|
||||
using Plugin.Fingerprint;
|
||||
using Plugin.Fingerprint.Abstractions;
|
||||
using Plugin.Settings.Abstractions;
|
||||
|
||||
|
@ -32,11 +23,6 @@ namespace Bit.Android
|
|||
|
||||
global::Xamarin.Forms.Forms.Init(this, bundle);
|
||||
|
||||
if(!Resolver.IsSet)
|
||||
{
|
||||
SetIoc();
|
||||
}
|
||||
|
||||
LoadApplication(new App.App(
|
||||
Resolver.Resolve<IAuthService>(),
|
||||
Resolver.Resolve<IDatabaseService>(),
|
||||
|
@ -79,37 +65,5 @@ namespace Bit.Android
|
|||
Console.WriteLine("A OnResume");
|
||||
base.OnResume();
|
||||
}
|
||||
|
||||
private void SetIoc()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container
|
||||
// Services
|
||||
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISecureStorageService, KeyStoreStorageService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
||||
// 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())
|
||||
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
|
||||
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
||||
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
||||
|
||||
Resolver.SetResolver(new UnityResolver(container));
|
||||
|
||||
UserDialogs.Init(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
144
src/Android/MainApplication.cs
Normal file
144
src/Android/MainApplication.cs
Normal file
|
@ -0,0 +1,144 @@
|
|||
using System;
|
||||
using Acr.UserDialogs;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Bit.Android.Services;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Repositories;
|
||||
using Bit.App.Services;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Plugin.Connectivity;
|
||||
using Plugin.CurrentActivity;
|
||||
using Plugin.Fingerprint;
|
||||
using Plugin.Settings;
|
||||
using PushNotification.Plugin;
|
||||
using PushNotification.Plugin.Abstractions;
|
||||
using XLabs.Ioc;
|
||||
using XLabs.Ioc.Unity;
|
||||
|
||||
namespace Bit.Android
|
||||
{
|
||||
[Application]
|
||||
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
|
||||
{
|
||||
public static Context AppContext;
|
||||
|
||||
public MainApplication(IntPtr handle, JniHandleOwnership transer)
|
||||
: base(handle, transer)
|
||||
{
|
||||
if(!Resolver.IsSet)
|
||||
{
|
||||
SetIoc();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
RegisterActivityLifecycleCallbacks(this);
|
||||
AppContext = ApplicationContext;
|
||||
StartPushService();
|
||||
Resolver.Resolve<IPushNotification>().Unregister();
|
||||
Resolver.Resolve<IPushNotification>().Register();
|
||||
}
|
||||
|
||||
public override void OnTerminate()
|
||||
{
|
||||
base.OnTerminate();
|
||||
UnregisterActivityLifecycleCallbacks(this);
|
||||
}
|
||||
|
||||
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivityDestroyed(Activity activity)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityPaused(Activity activity)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityResumed(Activity activity)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityStarted(Activity activity)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivityStopped(Activity activity)
|
||||
{
|
||||
}
|
||||
|
||||
public static void StartPushService()
|
||||
{
|
||||
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
|
||||
|
||||
if(global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Kitkat)
|
||||
{
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
|
||||
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||
alarm.Cancel(pintent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void StopPushService()
|
||||
{
|
||||
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
|
||||
if(global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Kitkat)
|
||||
{
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
|
||||
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||
alarm.Cancel(pintent);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetIoc()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container
|
||||
// Services
|
||||
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISecureStorageService, KeyStoreStorageService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IPushNotificationListener, PushNotificationListener>(new ContainerControlledLifetimeManager())
|
||||
// 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())
|
||||
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
|
||||
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
||||
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
||||
|
||||
CrossPushNotification.Initialize(container.Resolve<IPushNotificationListener>(), "SENDERID");
|
||||
container.RegisterInstance(CrossPushNotification.Current, new ContainerControlledLifetimeManager());
|
||||
|
||||
Resolver.SetResolver(new UnityResolver(container));
|
||||
CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);
|
||||
|
||||
UserDialogs.Init(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Bit.Android" android:versionCode="1" android:versionName="0.0.1" android:installLocation="auto">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bitwarden.vault" android:versionCode="1" android:versionName="0.0.1" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
<uses-permission android:name="com.bitwarden.vault.permission.C2D_MESSAGE" />
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<application android:label="bitwarden" android:theme="@style/BitwardenTheme"></application>
|
||||
</manifest>
|
5666
src/Android/Resources/Resource.Designer.cs
generated
5666
src/Android/Resources/Resource.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
@ -4,12 +4,14 @@
|
|||
<package id="Acr.UserDialogs" version="5.0.1" targetFramework="monoandroid60" />
|
||||
<package id="CommonServiceLocator" version="1.3" targetFramework="monoandroid60" />
|
||||
<package id="modernhttpclient" version="2.4.2" targetFramework="monoandroid50" />
|
||||
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
|
||||
<package id="Plugin.Fingerprint" version="1.1.1-beta" targetFramework="monoandroid60" />
|
||||
<package id="Splat" version="1.6.2" targetFramework="monoandroid60" />
|
||||
<package id="sqlite-net-pcl" version="1.1.1" targetFramework="monoandroid60" />
|
||||
<package id="SQLitePCL.raw" version="0.8.6" targetFramework="monoandroid60" />
|
||||
<package id="Unity" version="3.5.1405-prerelease" targetFramework="monoandroid60" />
|
||||
<package id="Xam.Plugin.Connectivity" version="2.1.2" targetFramework="monoandroid60" />
|
||||
<package id="Xam.Plugin.PushNotification" version="1.2.2" targetFramework="monoandroid60" developmentDependency="true" />
|
||||
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
|
||||
|
@ -20,6 +22,8 @@
|
|||
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Base" version="25.0.0.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Gcm" version="25.0.0.0" targetFramework="monoandroid60" />
|
||||
<package id="XLabs.IoC" version="2.0.5782" targetFramework="monoandroid60" />
|
||||
<package id="XLabs.IoC.Unity" version="2.0.5782" targetFramework="monoandroid60" />
|
||||
</packages>
|
|
@ -191,6 +191,14 @@
|
|||
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Settings.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\PushNotification.Plugin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\PushNotification.Plugin.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -226,7 +234,9 @@
|
|||
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\PushNotificationListener.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.2.0.31\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.2.0.31\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
|
51
src/App/Services/PushNotificationListener.cs
Normal file
51
src/App/Services/PushNotificationListener.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using PushNotification.Plugin.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PushNotification.Plugin;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Bit.App.Abstractions;
|
||||
|
||||
namespace Bit.App.Services
|
||||
{
|
||||
public class PushNotificationListener : IPushNotificationListener
|
||||
{
|
||||
private bool _showNotification;
|
||||
private readonly ISyncService _syncService;
|
||||
|
||||
public PushNotificationListener(ISyncService syncService)
|
||||
{
|
||||
_syncService = syncService;
|
||||
}
|
||||
|
||||
public void OnMessage(JObject values, DeviceType deviceType)
|
||||
{
|
||||
_showNotification = false;
|
||||
Debug.WriteLine("Message Arrived: {0}", JsonConvert.SerializeObject(values));
|
||||
}
|
||||
|
||||
public void OnRegistered(string token, DeviceType deviceType)
|
||||
{
|
||||
Debug.WriteLine(string.Format("Push Notification - Device Registered - Token : {0}", token));
|
||||
}
|
||||
|
||||
public void OnUnregistered(DeviceType deviceType)
|
||||
{
|
||||
Debug.WriteLine("Push Notification - Device Unnregistered");
|
||||
}
|
||||
|
||||
public void OnError(string message, DeviceType deviceType)
|
||||
{
|
||||
Debug.WriteLine(string.Format("Push notification error - {0}", message));
|
||||
}
|
||||
|
||||
public bool ShouldShowNotification()
|
||||
{
|
||||
return _showNotification;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
<package id="SQLitePCL.raw" version="0.8.6" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Unity" version="3.5.1405-prerelease" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Xam.Plugin.Connectivity" version="2.1.2" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Xam.Plugin.PushNotification" version="1.2.2" targetFramework="portable45-net45+win8+wpa81" developmentDependency="true" />
|
||||
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="XLabs.IoC" version="2.0.5782" targetFramework="portable45-net45+win8+wpa81" />
|
||||
|
|
|
@ -21,6 +21,7 @@ using System.Diagnostics;
|
|||
using Xamarin.Forms;
|
||||
using Bit.App;
|
||||
using Bit.iOS.Core.Services;
|
||||
using PushNotification.Plugin;
|
||||
|
||||
namespace Bit.iOS
|
||||
{
|
||||
|
@ -128,6 +129,43 @@ namespace Bit.iOS
|
|||
return true;
|
||||
}
|
||||
|
||||
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
|
||||
{
|
||||
if(CrossPushNotification.Current is IPushNotificationHandler)
|
||||
{
|
||||
((IPushNotificationHandler)CrossPushNotification.Current).OnErrorReceived(error);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
|
||||
{
|
||||
if(CrossPushNotification.Current is IPushNotificationHandler)
|
||||
{
|
||||
((IPushNotificationHandler)CrossPushNotification.Current).OnRegisteredSuccess(deviceToken);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DidRegisterUserNotificationSettings(UIApplication application, UIUserNotificationSettings notificationSettings)
|
||||
{
|
||||
application.RegisterForRemoteNotifications();
|
||||
}
|
||||
|
||||
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
|
||||
{
|
||||
if(CrossPushNotification.Current is IPushNotificationHandler)
|
||||
{
|
||||
((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
|
||||
{
|
||||
if(CrossPushNotification.Current is IPushNotificationHandler)
|
||||
{
|
||||
((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendLockMessage()
|
||||
{
|
||||
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Lock", false);
|
||||
|
@ -148,6 +186,7 @@ namespace Bit.iOS
|
|||
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IPushNotificationListener, PushNotificationListener>(new ContainerControlledLifetimeManager())
|
||||
// Repositories
|
||||
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
|
||||
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())
|
||||
|
@ -160,6 +199,9 @@ namespace Bit.iOS
|
|||
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
||||
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
||||
|
||||
CrossPushNotification.Initialize(container.Resolve<IPushNotificationListener>());
|
||||
container.RegisterInstance(CrossPushNotification.Current, new ContainerControlledLifetimeManager());
|
||||
|
||||
Resolver.SetResolver(new UnityResolver(container));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,5 +75,9 @@
|
|||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -168,6 +168,10 @@
|
|||
<HintPath>..\..\packages\modernhttpclient.2.4.2\lib\Xamarin.iOS10\ModernHttpClient.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Connectivity, Version=2.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.Connectivity.2.1.2\lib\Xamarin.iOS10\Plugin.Connectivity.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -192,6 +196,14 @@
|
|||
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\Xamarin.iOS10\PushNotification.Plugin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PushNotification.Plugin.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xam.Plugin.PushNotification.1.2.2\lib\Xamarin.iOS10\PushNotification.Plugin.Abstractions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Splat.1.6.2\lib\Xamarin.iOS10\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
<package id="Acr.UserDialogs" version="5.0.1" targetFramework="xamarinios10" />
|
||||
<package id="CommonServiceLocator" version="1.3" targetFramework="xamarinios10" />
|
||||
<package id="modernhttpclient" version="2.4.2" targetFramework="xamarinios10" />
|
||||
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="xamarinios10" />
|
||||
<package id="Plugin.Fingerprint" version="1.1.1-beta" targetFramework="xamarinios10" />
|
||||
<package id="Splat" version="1.6.2" targetFramework="xamarinios10" />
|
||||
<package id="sqlite-net-pcl" version="1.1.1" targetFramework="xamarinios10" />
|
||||
<package id="SQLitePCL.raw" version="0.8.6" targetFramework="xamarinios10" />
|
||||
<package id="Unity" version="3.5.1405-prerelease" targetFramework="xamarinios10" />
|
||||
<package id="Xam.Plugin.Connectivity" version="2.1.2" targetFramework="xamarinios10" />
|
||||
<package id="Xam.Plugin.PushNotification" version="1.2.2" targetFramework="xamarinios10" developmentDependency="true" />
|
||||
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="xamarinios10" />
|
||||
<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="xamarinios10" />
|
||||
<package id="XLabs.IoC" version="2.0.5782" targetFramework="xamarinios10" />
|
||||
|
|
Loading…
Reference in a new issue