Beispiel #1
0
        public static bool UseNotifications(this IServiceCollection builder, Action <AndroidOptions, UwpOptions> configure = null)
        {
            if (configure != null)
            {
                var androidOpts = new AndroidOptions();
                var uwpOpts     = new UwpOptions();
                configure(androidOpts, uwpOpts);

                AndroidOptions.DefaultChannel                = androidOpts.ChannelDescription ?? AndroidOptions.DefaultChannel;
                AndroidOptions.DefaultChannelDescription     = androidOpts.ChannelDescription ?? AndroidOptions.DefaultChannelDescription;
                AndroidOptions.DefaultChannelId              = androidOpts.ChannelId ?? AndroidOptions.DefaultChannelId;
                AndroidOptions.DefaultNotificationImportance = androidOpts.NotificationImportance;
                AndroidOptions.DefaultLaunchActivityFlags    = androidOpts.LaunchActivityFlags;
                AndroidOptions.DefaultVibrate                = androidOpts.Vibrate;
                AndroidOptions.DefaultSmallIconResourceName  = androidOpts.SmallIconResourceName ?? AndroidOptions.DefaultSmallIconResourceName;

                UwpOptions.DefaultUseLongDuration = uwpOpts.UseLongDuration;
            }

#if NETSTANDARD
            return(false);
#else
            builder.AddSingleton <INotificationManager, NotificationManagerImpl>();
            return(true);
#endif
        }
        public static bool UseNotifications(this IServiceCollection builder,
                                            bool requestPermissionImmediately        = false,
                                            Action <AndroidOptions> androidConfigure = null,
                                            Action <UwpOptions> uwpConfigure         = null)
        {
            if (androidConfigure != null)
            {
                var androidOpts = new AndroidOptions();
                androidConfigure(androidOpts);

                AndroidOptions.DefaultChannel                = androidOpts.ChannelDescription ?? AndroidOptions.DefaultChannel;
                AndroidOptions.DefaultChannelDescription     = androidOpts.ChannelDescription ?? AndroidOptions.DefaultChannelDescription;
                AndroidOptions.DefaultChannelId              = androidOpts.ChannelId ?? AndroidOptions.DefaultChannelId;
                AndroidOptions.DefaultNotificationImportance = androidOpts.NotificationImportance;
                AndroidOptions.DefaultLaunchActivityFlags    = androidOpts.LaunchActivityFlags;
                AndroidOptions.DefaultVibrate                = androidOpts.Vibrate;
                AndroidOptions.DefaultSmallIconResourceName  = androidOpts.SmallIconResourceName ?? AndroidOptions.DefaultSmallIconResourceName;
            }
            if (uwpConfigure != null)
            {
                var uwpOpts = new UwpOptions();
                uwpConfigure(uwpOpts);
                UwpOptions.DefaultUseLongDuration = uwpOpts.UseLongDuration;
            }

#if __ANDROID__ || WINDOWS_UWP
            builder.RegisterJob(new Jobs.JobInfo
            {
                Identifier = nameof(NotificationJob),
                Type       = typeof(NotificationJob),
                Repeat     = true
            });
#endif

#if NETSTANDARD
            return(false);
#else
            if (requestPermissionImmediately)
            {
                builder.RegisterPostBuildAction(async sp =>
                                                await sp
                                                .GetService <INotificationManager>()
                                                .RequestAccess()
                                                );
            }
            builder.AddSingleton <INotificationManager, NotificationManagerImpl>();
            return(true);
#endif
        }
Beispiel #3
0
 public NotificationModule(bool requestPermissionImmediately,
                           AndroidOptions androidConfig,
                           UwpOptions uwpConfig)
 {
     this.requestPermissionImmediately = requestPermissionImmediately;
     if (androidConfig != null)
     {
         AndroidOptions.DefaultChannel                = androidConfig.ChannelDescription ?? AndroidOptions.DefaultChannel;
         AndroidOptions.DefaultChannelDescription     = androidConfig.ChannelDescription ?? AndroidOptions.DefaultChannelDescription;
         AndroidOptions.DefaultChannelId              = androidConfig.ChannelId ?? AndroidOptions.DefaultChannelId;
         AndroidOptions.DefaultNotificationImportance = androidConfig.NotificationImportance;
         AndroidOptions.DefaultLaunchActivityFlags    = androidConfig.LaunchActivityFlags;
         AndroidOptions.DefaultVibrate                = androidConfig.Vibrate;
         AndroidOptions.DefaultSmallIconResourceName  = androidConfig.SmallIconResourceName ?? AndroidOptions.DefaultSmallIconResourceName;
     }
     if (uwpConfig != null)
     {
         UwpOptions.DefaultUseLongDuration = uwpConfig.UseLongDuration;
     }
 }