Example #1
0
        // 启动一个“轮询服务端以更新 badge 通知”的任务
        private void btnStartPeriodicUpdate_Click(object sender, RoutedEventArgs e)
        {
            // 启动一个循环更新 Badge 通知的任务,并指定 Badge 通知的数据源和轮询周期
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            // 马上请求服务端获取数据,然后 45 分钟之后再次获取数据,最后再每半个小时获取一次数据
            badgeUpdater.StartPeriodicUpdate(new Uri("http://localhost:44914/api/BadgeContent", UriKind.Absolute), DateTimeOffset.UtcNow.AddMinutes(45), PeriodicUpdateRecurrence.HalfHour);

            // Badge 通知的数据源示例请参见 WebApi/Controllers/BadgeContentController.cs
        }
Example #2
0
        /// <summary>
        /// Método que configura a URL das live tiles do aplicativo.
        /// </summary>
        public static void CreateTile()
        {
            var uris = new List <Uri>();

            for (int i = 0; i < 5; i++)
            {
                uris.Add(new Uri("http://" + backendUrl + "notifications/tiles/tile.php" + finalUrl + "&tile=" + i));
            }

            TileUpdater LiveTileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            LiveTileUpdater.Clear();
            LiveTileUpdater.EnableNotificationQueue(true);
            LiveTileUpdater.StartPeriodicUpdateBatch(uris, PeriodicUpdateRecurrence.Daily);

            BadgeUpdater BadgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            BadgeUpdater.Clear();
            BadgeUpdater.StartPeriodicUpdate(new Uri("http://" + backendUrl + "notifications/tiles/badge.php" + finalUrl), PeriodicUpdateRecurrence.Daily);
        }
Example #3
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                Xamarin.Forms.Forms.Init(e);
                Xamarin.Forms.DependencyService.Register <Dependencies_UWP>();

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                var uris = new List <Uri>();

                for (int i = 0; i < 5; i++)
                {
                    uris.Add(new Uri("http://" + Other.Other.GetBackendUrl() + "notifications/tiles/tile.php" + Other.Other.GetFinalUrl() + "&tile=" + i));
                }

                TileUpdater LiveTileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
                LiveTileUpdater.Clear();
                LiveTileUpdater.EnableNotificationQueue(true);
                LiveTileUpdater.StartPeriodicUpdateBatch(uris, PeriodicUpdateRecurrence.Daily);

                BadgeUpdater BadgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
                BadgeUpdater.Clear();
                BadgeUpdater.StartPeriodicUpdate(new Uri("http://" + Other.Other.GetBackendUrl() + "notifications/tiles/badge.php" + Other.Other.GetFinalUrl()), PeriodicUpdateRecurrence.Daily);

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #4
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 1;

                Xamarin.Forms.Forms.Init(e);
                Xamarin.Forms.DependencyService.Register <Dependencies_WinPhone>();

                ImageCircleRenderer.Init();
                WindowsRuntimeResourceManager.PatchResourceManagersInAssembly(typeof(Resx.AppResources));

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                var uris = new List <Uri>();

                for (int i = 0; i < 5; i++)
                {
                    uris.Add(new Uri("http://" + Other.Other.GetBackendUrl() + "notifications/tiles/tile.php" + Other.Other.GetFinalUrl() + "&tile=" + i));
                }

                TileUpdater LiveTileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
                LiveTileUpdater.Clear();
                LiveTileUpdater.EnableNotificationQueue(true);
                LiveTileUpdater.StartPeriodicUpdateBatch(uris, PeriodicUpdateRecurrence.Daily);

                BadgeUpdater BadgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
                BadgeUpdater.Clear();
                BadgeUpdater.StartPeriodicUpdate(new Uri("http://" + Other.Other.GetBackendUrl() + "notifications/tiles/badge.php" + Other.Other.GetFinalUrl()), PeriodicUpdateRecurrence.Daily);

                string colorPrimary = Other.Other.GetColorPrimary();

                byte a = byte.Parse(colorPrimary.Substring(1, 2), NumberStyles.HexNumber);
                byte r = byte.Parse(colorPrimary.Substring(3, 2), NumberStyles.HexNumber);
                byte g = byte.Parse(colorPrimary.Substring(5, 2), NumberStyles.HexNumber);
                byte b = byte.Parse(colorPrimary.Substring(7, 2), NumberStyles.HexNumber);

                StatusBar.GetForCurrentView().ForegroundColor   = Colors.White;
                StatusBar.GetForCurrentView().BackgroundColor   = Color.FromArgb(a, r, g, b);
                StatusBar.GetForCurrentView().BackgroundOpacity = 1;

                OneSignal.Init(Other.Other.GetOneSignalAppId(), e, (message, additionalData, isActivity) => {
                    if (additionalData.ContainsKey("eventid"))
                    {
                        GDG_SP.MainPage.openEvent = int.Parse(additionalData["eventid"]);
                    }
                });

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += this.RootFrame_FirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }