コード例 #1
0
        public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            // Payload reference: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification

            /*
             * {
             *   "content-available": 1
             *   "action": "syncAccount",
             *   "accountId": 49831
             * }
             * */

            try
            {
                if (userInfo.TryGetValue(new NSString("action"), out NSObject actionValue) &&
                    actionValue is NSString actionValueStr &&
                    actionValueStr == "syncAccount" &&
                    userInfo.TryGetValue(new NSString("accountId"), out NSObject accountIdValue) &&
                    accountIdValue is NSNumber accountIdNum)
                {
                    long accountId = accountIdNum.Int64Value;

                    await PowerPlannerApp.SyncAccountInBackgroundAsync(accountId);
                }
            }
            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }

            try
            {
                completionHandler(UIBackgroundFetchResult.NewData);
            }
            catch { }
        }
コード例 #2
0
        protected override async Task PerformWorkAsync(JobParameters @params)
        {
            long accountId = @params.Extras.GetLong("AccountId");

            await PowerPlannerApp.SyncAccountInBackgroundAsync(accountId);
        }