зеркало из https://github.com/xamarin/ios-samples.git
[SimpleBackgroundTransfer] Fix #71(#37341 in bugzilla) + code formatting and refactoring
This commit is contained in:
Родитель
563f0eef02
Коммит
8479a5b871
|
@ -3,10 +3,8 @@ using Foundation;
|
|||
using UIKit;
|
||||
|
||||
namespace SimpleBackgroundTransfer {
|
||||
|
||||
[Register ("AppDelegate")]
|
||||
public partial class AppDelegate : UIApplicationDelegate {
|
||||
|
||||
public class AppDelegate : UIApplicationDelegate {
|
||||
public Action BackgroundSessionCompletionHandler { get; set; }
|
||||
|
||||
public override UIWindow Window { get; set; }
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
<key>UIMainStoryboardFile</key>
|
||||
<string>MainStoryboard</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>7.0</string>
|
||||
<string>9.0</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.SimpleBackgroundTransfer.BackgroundSession</string>
|
||||
<string>com.xamarin.BackgroundSession</string>
|
||||
<key>CFBundleIconFiles</key>
|
||||
<array>
|
||||
<string>Icon</string>
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace SimpleBackgroundTransfer
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
namespace SimpleBackgroundTransfer {
|
||||
public class Application {
|
||||
// This is the main entry point of the application.
|
||||
static void Main (string[] args)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using CoreGraphics;
|
||||
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace SimpleBackgroundTransfer {
|
|||
public NSUrlSession InitBackgroundSession ()
|
||||
{
|
||||
Console.WriteLine ("InitBackgroundSession");
|
||||
using (var configuration = NSUrlSessionConfiguration.BackgroundSessionConfiguration (Identifier)) {
|
||||
using (var configuration = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration (Identifier)) {
|
||||
return NSUrlSession.FromConfiguration (configuration, new UrlSessionDelegate (this), null);
|
||||
}
|
||||
}
|
||||
|
@ -144,12 +144,14 @@ namespace SimpleBackgroundTransfer {
|
|||
|
||||
public override void DidFinishEventsForBackgroundSession (NSUrlSession session)
|
||||
{
|
||||
AppDelegate appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
|
||||
var handler = appDelegate.BackgroundSessionCompletionHandler;
|
||||
if (handler != null) {
|
||||
appDelegate.BackgroundSessionCompletionHandler = null;
|
||||
handler ();
|
||||
using (AppDelegate appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate) {
|
||||
var handler = appDelegate.BackgroundSessionCompletionHandler;
|
||||
if (handler != null) {
|
||||
appDelegate.BackgroundSessionCompletionHandler = null;
|
||||
handler();
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine ("All tasks are finished");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче