当前位置: 首页>>代码示例>>C#>>正文


C# NSUrlSession类代码示例

本文整理汇总了C#中NSUrlSession的典型用法代码示例。如果您正苦于以下问题:C# NSUrlSession类的具体用法?C# NSUrlSession怎么用?C# NSUrlSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NSUrlSession类属于命名空间,在下文中一共展示了NSUrlSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DidFinishDownloading

	    public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
	    {
	        if (!downloadTasks.ContainsKey(downloadTask.TaskIdentifier))
	            return;

			var cachedTaskInfo  = downloadTasks[downloadTask.TaskIdentifier];

			try
			{
                OnFileDownloadProgress(cachedTaskInfo.Index, 100f);

                var tmpLocation = location.Path;
				var dirName     = Path.GetDirectoryName(cachedTaskInfo.DestinationDiskPath);

				if (!Directory.Exists(dirName))
					Directory.CreateDirectory(dirName);

				if (File.Exists(cachedTaskInfo.DestinationDiskPath))
					File.Delete(cachedTaskInfo.DestinationDiskPath);

				File.Move(tmpLocation, cachedTaskInfo.DestinationDiskPath);
                OnFileDownloadedSuccessfully(cachedTaskInfo.Index, cachedTaskInfo.DestinationDiskPath);
                CleanUpCachedTask(cachedTaskInfo);
            }

			catch (Exception exception)
			{
				OnError(cachedTaskInfo, new NSError(new NSString(exception.Message), 1));
			}
		}
开发者ID:raghurana,项目名称:NsUrlDownloadDemo,代码行数:30,代码来源:HttpFilesDownloadSession.cs

示例2: DidFinishEventsForBackgroundSession

		public override void DidFinishEventsForBackgroundSession (NSUrlSession session)
		{
			var handler = AppDelegate.BackgroundSessionCompletionHandler;
			AppDelegate.BackgroundSessionCompletionHandler = null;
			if (handler != null) {
				handler.Invoke ();
			}
		}
开发者ID:xamarindevelopervietnam,项目名称:XamarinFormsBackgrounding,代码行数:8,代码来源:CustomSessionDownloadDelegate.cs

示例3: DidFinishEventsForBackgroundSession

 public override void DidFinishEventsForBackgroundSession(NSUrlSession session)
 {
     if (HttpService.BackgroundSessionCompletionHandler != null)
     {
         Action handler = HttpService.BackgroundSessionCompletionHandler;
         HttpService.BackgroundSessionCompletionHandler = null;
         handler.Invoke();
     }
 }
开发者ID:StorozhenkoDmitry,项目名称:SimpleHttp,代码行数:9,代码来源:DownloadDelegate.cs

示例4: NativeMessageHandler

        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification)
        {
            session = NSUrlSession.FromConfiguration(
                NSUrlSessionConfiguration.DefaultSessionConfiguration, 
                new DataTaskDelegate(this), null);

            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;
            this.customSSLVerification = customSSLVerification;
        }
开发者ID:rickykaare,项目名称:ModernHttpClient,代码行数:9,代码来源:NSUrlSessionHandler.cs

示例5: DidCompleteWithError

        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error != null)
            {
                TaskDescription description = JsonParser.ParseTaskDescription(task.TaskDescription).Result;

                OnDownloadCompleted("", task.TaskDescription ?? "", error.LocalizedDescription);
            }
        }
开发者ID:StorozhenkoDmitry,项目名称:SimpleHttp,代码行数:9,代码来源:DownloadDelegate.cs

示例6: Init

 public void Init(string sessionId, string url, TransferTaskMode mode)
 {
     using (var configuration = NSUrlSessionConfiguration.BackgroundSessionConfiguration(sessionId))
     {
         _mode = mode;
         _sessionId = sessionId;
         _url = url;
         session = NSUrlSession.FromConfiguration(configuration);
     }
 }
开发者ID:garymedina,项目名称:OfflineSyncApp,代码行数:10,代码来源:BackgroundTransferTaskIOS.cs

示例7: DidCompleteWithError

		public override void DidCompleteWithError (NSUrlSession session, NSUrlSessionTask task, NSError error)
		{
			if (error == null) {
				return;
			}

			Console.WriteLine ("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);

			task.Cancel ();
		}
开发者ID:xamarindevelopervietnam,项目名称:XamarinFormsBackgrounding,代码行数:10,代码来源:CustomSessionDownloadDelegate.cs

示例8: DidWriteData

	    public override void DidWriteData(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, long bytesWritten, long totalBytesWritten, long totalBytesExpectedToWrite)
	    {
	        if (downloadTasks.ContainsKey(downloadTask.TaskIdentifier))
	        {
	            var index = downloadTasks[downloadTask.TaskIdentifier].Index;
	            var progress = totalBytesWritten/(float) totalBytesExpectedToWrite;

	            OnFileDownloadProgress(index, progress);
	        }
	    }
开发者ID:raghurana,项目名称:NsUrlDownloadDemo,代码行数:10,代码来源:HttpFilesDownloadSession.cs

示例9: HttpFilesDownloadSession

		public HttpFilesDownloadSession(string uniqueSessionId)
		{
			var config      = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(uniqueSessionId);

			downloadSession = NSUrlSession.FromConfiguration(config, this, new NSOperationQueue());
			downloadTasks   = new Dictionary<nuint, DownloadTaskInfo>();

			DownloadQueue   = new ObservableCollection<DownloadFileInfo>();
			DownloadQueue.CollectionChanged += DownloadQueueOnCollectionChanged;
		}
开发者ID:raghurana,项目名称:NsUrlDownloadDemo,代码行数:10,代码来源:HttpFilesDownloadSession.cs

示例10: DidWriteData

		public override void DidWriteData (NSUrlSession session, NSUrlSessionDownloadTask downloadTask, long bytesWritten, long totalBytesWritten, long totalBytesExpectedToWrite)
		{
			Console.WriteLine ("Set Progress");
			if (downloadTask == controller.downloadTask) {
				float progress = totalBytesWritten / (float)totalBytesExpectedToWrite;
				Console.WriteLine (string.Format ("DownloadTask: {0}  progress: {1}", downloadTask, progress));
				InvokeOnMainThread( () => {
					controller.ProgressView.Progress = progress;
				});
			}
		}
开发者ID:g7steve,项目名称:monotouch-samples,代码行数:11,代码来源:SimpleBackgroundTransferViewController.cs

示例11: NativeMessageHandler

        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification, NativeCookieHandler cookieHandler = null)
        {
            session = NSUrlSession.FromConfiguration(
                NSUrlSessionConfiguration.DefaultSessionConfiguration, 
                new DataTaskDelegate(this), null);

            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;
            this.customSSLVerification = customSSLVerification;

            this.DisableCaching = false;
        }
开发者ID:AMcKane,项目名称:ModernHttpClient,代码行数:11,代码来源:NSUrlSessionHandler.cs

示例12: DidFinishDownloading

		public override void DidFinishDownloading (NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
		{
			CopyDownloadedImage (location);

			var message = new DownloadFinishedMessage () {
				FilePath = targetFileName,
				Url = downloadTask.OriginalRequest.Url.AbsoluteString
			};

			MessagingCenter.Send<DownloadFinishedMessage> (message, "DownloadFinishedMessage");

		}
开发者ID:xamarindevelopervietnam,项目名称:XamarinFormsBackgrounding,代码行数:12,代码来源:CustomSessionDownloadDelegate.cs

示例13: DidWriteData

		public override void DidWriteData (NSUrlSession session, NSUrlSessionDownloadTask downloadTask, long bytesWritten, long totalBytesWritten, long totalBytesExpectedToWrite)
		{
			float percentage = (float)totalBytesWritten / (float)totalBytesExpectedToWrite;

			var message = new DownloadProgressMessage () {
				BytesWritten = bytesWritten,
				TotalBytesExpectedToWrite = totalBytesExpectedToWrite,
				TotalBytesWritten = totalBytesWritten,
				Percentage = percentage
			};

			MessagingCenter.Send<DownloadProgressMessage> (message, "DownloadProgressMessage");
		}
开发者ID:xamarindevelopervietnam,项目名称:XamarinFormsBackgrounding,代码行数:13,代码来源:CustomSessionDownloadDelegate.cs

示例14: InitializeSession

		void InitializeSession ()
		{
			using (var sessionConfig = UIDevice.CurrentDevice.CheckSystemVersion (8, 0)
				? NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration (sessionId)
				: NSUrlSessionConfiguration.BackgroundSessionConfiguration (sessionId)) {
				sessionConfig.AllowsCellularAccess = true;

				sessionConfig.NetworkServiceType = NSUrlRequestNetworkServiceType.Default;

				sessionConfig.HttpMaximumConnectionsPerHost = 2;

				var sessionDelegate = new CustomSessionDownloadDelegate (targetFilename);
				this.session = NSUrlSession.FromConfiguration (sessionConfig, sessionDelegate, null);
			}
		}
开发者ID:xamarindevelopervietnam,项目名称:XamarinFormsBackgrounding,代码行数:15,代码来源:Downloader.cs

示例15: NetworkUrlSession

        public NetworkUrlSession(string identifier)
        {
            _transfers = new List<NetworkUrlSessionTransfer> (10);
            _urlSessionDelegate = new NetworkUrlSessionDelegate (this);

            NSUrlSessionConfiguration c = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration (identifier);
            NSOperationQueue q = new NSOperationQueue ();
            // only allow 1 file transfer at a time; SAMCTODO: not sure if this is best..
            q.MaxConcurrentOperationCount = 1;
            _urlSession = NSUrlSession.FromConfiguration (c, _urlSessionDelegate, q);
            _urlSession.GetTasks( HandleNSUrlSessionPendingTasks );
            IBackgroundUrlEventDispatcher appDelegate = UIApplication.SharedApplication.Delegate as IBackgroundUrlEventDispatcher;

            appDelegate.HandleEventsForBackgroundUrlEvent += HandleEventsForBackgroundUrl;
        }
开发者ID:ruiamorimwDev,项目名称:skobbler-mono-bindings,代码行数:15,代码来源:NetworkUrlSession.cs


注:本文中的NSUrlSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。