[Foundation] Allow uses to explicitly bypass the background session check. #6443 (#6918)

Issue was reponed because users had a valid reason to want to bypass
this security check. The HttpClient should be able to work in a
background task. So we now provide a way for users to explicitly ignore
the check.

Fixes: https://github.com/xamarin/xamarin-macios/issues/6443
This commit is contained in:
Manuel de la Pena 2019-09-05 19:12:16 -04:00 коммит произвёл GitHub
Родитель 4a08c6c7b2
Коммит 844ca7ccf4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -183,7 +183,7 @@ namespace Foundation {
void AddNotification ()
{
lock (notificationTokenLock) {
if (!isBackgroundSession && notificationToken == null)
if (!bypassBackgroundCheck && !isBackgroundSession && notificationToken == null)
notificationToken = NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillResignActiveNotification, BackgroundNotificationCb);
} // lock
}
@ -316,6 +316,22 @@ namespace Foundation {
}
}
// we do check if a user does a request and the application goes to the background, but
// in certain cases the user does that on purpose (BeingBackgroundTask) and wants to be able
// to use the network. In those cases, which are few, we want the developer to explicitly
// bypass the check when there are not request in flight
bool bypassBackgroundCheck;
public bool BypassBackgroundSessionCheck {
get {
return bypassBackgroundCheck;
}
set {
EnsureModifiability ();
bypassBackgroundCheck = value;
}
}
bool sentRequest;
internal void EnsureModifiability ()