Exemple #1
0
        /// <summary>
        /// Initializes the session.
        /// </summary>
        void InitializeSession()
        {
            // Initialize our session config. We use a background session to enabled out of process uploads/downloads. Note that there are other configurations available:
            // - DefaultSessionConfiguration: behaves like NSUrlConnection. Used if *background* transfer is not required.
            // - EphemeralSessionConfiguration: use if you want to achieve something like private browsing where all sesion info (e.g. cookies) is kept in memory only.
            using (var sessionConfig = UIDevice.CurrentDevice.CheckSystemVersion(8, 0)
                                ? NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(sessionId)
                                : NSUrlSessionConfiguration.BackgroundSessionConfiguration(sessionId))
            {
                // Allow downloads over cellular network too.
                sessionConfig.AllowsCellularAccess = true;

                // Give the OS a hint about what we are downloading. This helps iOS to prioritize. For example "Background" is used to download data that was not requested by the user and
                // should be ready if the app gets activated.
                sessionConfig.NetworkServiceType = NSUrlRequestNetworkServiceType.Default;

                // Configure how many downloads we allow at the same time. Set to 2 to see that further downloads start once the first two have been completed.
                sessionConfig.HttpMaximumConnectionsPerHost = 2;

                // Create a session delegate and the session itself
                // Initialize the session itself with the configuration and a session delegate.
                var sessionDelegate = new CustomSessionDownloadDelegate(this);
                this.session = NSUrlSession.FromConfiguration(sessionConfig, (INSUrlSessionDelegate)sessionDelegate, null);
            }
        }
 /// <summary>
 /// Initializes the session.
 /// </summary>
 void InitializeSession()
 {
     // TODO: Initialize NSUrlSession.
     using (var sessionConfig = UIDevice.CurrentDevice.CheckSystemVersion(8, 0)
         ? NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(sessionId)
         : NSUrlSessionConfiguration.BackgroundSessionConfiguration(sessionId))
     {
         sessionConfig.AllowsCellularAccess = true;
         sessionConfig.NetworkServiceType   = NSUrlRequestNetworkServiceType.Default;
         var sessionDelegate = new CustomSessionDownloadDelegate(this);
         this.session = NSUrlSession.FromConfiguration(sessionConfig, sessionDelegate, null);
     }
 }