コード例 #1
0
        internal static MauiAppBuilder UseEssentials(this MauiAppBuilder builder)
        {
            builder.ConfigureLifecycleEvents(life =>
            {
#if __ANDROID__
                Platform.Init(MauiApplication.Current);

                life.AddAndroid(android => android
                                .OnCreate((activity, savedInstanceState) =>
                {
                    Platform.Init(activity, savedInstanceState);
                })
                                .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) =>
                {
                    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
                })
                                .OnNewIntent((activity, intent) =>
                {
                    Platform.OnNewIntent(intent);
                })
                                .OnResume((activity) =>
                {
                    Platform.OnResume();
                }));
#elif __IOS__
                life.AddiOS(ios => ios
                            .ContinueUserActivity((application, userActivity, completionHandler) =>
                {
                    return(Platform.ContinueUserActivity(application, userActivity, completionHandler));
                })
                            .OpenUrl((application, url, options) =>
                {
                    return(Platform.OpenUrl(application, url, options));
                })
                            .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
                {
                    Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler);
                }));
#elif WINDOWS
                life.AddWindows(windows => windows
                                .OnNativeMessage((window, args) =>
                {
                    Platform.NewWindowProc(args.Hwnd, args.MessageId, args.WParam, args.LParam);
                })
                                .OnActivated((window, args) =>
                {
                    Platform.OnActivated(window, args);
                })
                                .OnLaunched((application, args) =>
                {
                    Platform.OnLaunched(args);
                }));
#endif
            });

            return(builder);
        }
コード例 #2
0
        public static MauiAppBuilder ConfigureEssentials(this MauiAppBuilder builder, Action <IEssentialsBuilder> configureDelegate = null)
        {
            if (configureDelegate != null)
            {
                builder.Services.AddSingleton <EssentialsRegistration>(new EssentialsRegistration(configureDelegate));
            }
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IMauiInitializeService, EssentialsInitializer>());

            builder.ConfigureLifecycleEvents(life =>
            {
#if __ANDROID__
                Platform.Init(MauiApplication.Current);

                life.AddAndroid(android => android
                                .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) =>
                {
                    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
                })
                                .OnNewIntent((activity, intent) =>
                {
                    Platform.OnNewIntent(intent);
                })
                                .OnResume((activity) =>
                {
                    Platform.OnResume();
                }));
#elif __IOS__
                life.AddiOS(ios => ios
                            .ContinueUserActivity((application, userActivity, completionHandler) =>
                {
                    return(Platform.ContinueUserActivity(application, userActivity, completionHandler));
                })
                            .OpenUrl((application, url, options) =>
                {
                    return(Platform.OpenUrl(application, url, options));
                })
                            .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
                {
                    Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler);
                }));
#elif WINDOWS
                life.AddWindows(windows => windows
                                .OnActivated((window, args) =>
                {
                    Platform.OnActivated(window, args);
                })
                                .OnLaunched((application, args) =>
                {
                    Platform.OnLaunched(args);
                }));
#endif
            });

            return(builder);
        }
コード例 #3
0
        public static IAppHostBuilder ConfigureEssentials(this IAppHostBuilder builder, Action <HostBuilderContext, IEssentialsBuilder> configureDelegate = null)
        {
            builder.ConfigureLifecycleEvents(life =>
            {
#if __ANDROID__
                Platform.Init(MauiApplication.Current);

                life.AddAndroid(android => android
                                .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) =>
                {
                    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
                })
                                .OnNewIntent((activity, intent) =>
                {
                    Platform.OnNewIntent(intent);
                })
                                .OnResume((activity) =>
                {
                    Platform.OnResume();
                }));
#elif __IOS__
                life.AddiOS(ios => ios
                            .ContinueUserActivity((application, userActivity, completionHandler) =>
                {
                    return(Platform.ContinueUserActivity(application, userActivity, completionHandler));
                })
                            .OpenUrl((application, url, options) =>
                {
                    return(Platform.OpenUrl(application, url, options));
                })
                            .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
                {
                    Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler);
                }));
#elif WINDOWS
                life.AddWindows(windows => windows
                                .OnLaunched((application, args) =>
                {
                    Platform.OnLaunched(args);
                }));
#endif
            });

            if (configureDelegate != null)
            {
                builder.ConfigureServices <EssentialsBuilder>(configureDelegate);
            }

            return(builder);
        }