本文整理汇总了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));
}
}
示例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();
}
}
示例4: NativeMessageHandler
public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification)
{
session = NSUrlSession.FromConfiguration(
NSUrlSessionConfiguration.DefaultSessionConfiguration,
new DataTaskDelegate(this), null);
this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;
this.customSSLVerification = customSSLVerification;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
});
}
}
示例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;
}
示例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);
}
}
示例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;
}