本文整理汇总了C#中NSUrlRequest类的典型用法代码示例。如果您正苦于以下问题:C# NSUrlRequest类的具体用法?C# NSUrlRequest怎么用?C# NSUrlRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NSUrlRequest类属于命名空间,在下文中一共展示了NSUrlRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NSUrlConnectionWrapper
public NSUrlConnectionWrapper(NSUrlRequest request, EscozUrlStreamDelegate del) : base(request, del, true)
{
if (Connections.ContainsKey(del.Name)) {
KillConnection(del.Name);
}
Connections.Add(del.Name, this);
}
示例2: RequestImage
public bool RequestImage(string url, IImageUpdated receiver) {
var local = RequestLocalImage(url);
if (local != null) {
receiver.UpdatedImage(url, local);
return true;
}
if (pendingRequests.ContainsKey(url)){
pendingRequests[url].Add(receiver);
} else {
pendingRequests.Add(url, new List<IImageUpdated>(){receiver});
}
NSUrlRequest req = new NSUrlRequest(new NSUrl(url), NSUrlRequestCachePolicy.ReturnCacheDataElseLoad, 10);
new UrlConnection("img"+url, req, (UIImage img)=>{
var surl = url;
cache[surl] = img;
var imgreq = pendingRequests[surl];
foreach (var v in imgreq)
v.UpdatedImage(surl, img);
pendingRequests.Remove(surl);
});
return false;
}
示例3: SetupUserInterface
private void SetupUserInterface ()
{
scrollView = new UIScrollView {
BackgroundColor = UIColor.Clear.FromHexString ("#094074", 1.0f),
Frame = new CGRect (0, 0, Frame.Width, Frame.Height * 2)
};
licensureLabel = new UILabel {
Font = UIFont.FromName ("SegoeUI-Light", 25f),
Frame = new CGRect (0, 20, Frame.Width, 35),
Text = "Open-Source",
TextAlignment = UITextAlignment.Center,
TextColor = UIColor.White
};
string localHtmlUrl = Path.Combine (NSBundle.MainBundle.BundlePath, "Licensure.html");
var url = new NSUrl (localHtmlUrl, false);
var request = new NSUrlRequest (url);
webView = new UIWebView () {
Frame = new CGRect (0, 55, Frame.Width, Frame.Height - 55)
};
webView.LoadRequest (request);
scrollView.ContentSize = new CGSize (Frame.Width, Frame.Height * 2);
scrollView.Add (licensureLabel);
scrollView.Add (webView);
Add (scrollView);
}
示例4: DownloadFileAsync
public async Task<nuint> DownloadFileAsync (Uri url, string destination)
{
this.Url = url.AbsoluteUri;
if (downloadTask != null)
return downloadTask.TaskIdentifier;
if (session == null) {
Initalize ();
}
Destination = destination;
SessionId = session.Configuration.Identifier;
if (!BackgroundDownloadManager.Tasks.TryGetValue (url.AbsoluteUri, out Tcs)) {
Tcs = new TaskCompletionSource<bool> ();
BackgroundDownloadManager.Tasks.Add (url.AbsoluteUri, Tcs);
using (var request = new NSUrlRequest (new NSUrl (url.AbsoluteUri))) {
downloadTask = session.CreateDownloadTask (request);
downloadTask.Resume ();
}
}
BackgroundDownloadManager.AddController (this.Url, this);
await Tcs.Task;
return downloadTask.TaskIdentifier;
}
示例5: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
NSUrl url1 = new NSUrl(url);
NSUrlRequest request = new NSUrlRequest(url1);
webView.LoadRequest(request);
this.NavigationController.NavigationBar.Hidden = false;
this.NavigationController.NavigationBar.TintColor = UIColor.White;
this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB(44/255f,146/255f,208/255f);
this.NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes (){
ForegroundColor = UIColor.White,
Font = UIFont.FromName("System Bold",20.0f)
};
Title = name;
this.NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(
"Cancel", UIBarButtonItemStyle.Plain, (sender, args) => {
this.NavigationController.PopViewController(true);
}), true);
btn_close.TouchUpInside += (object sender, EventArgs e) => {
this.NavigationController.PopViewController(true);
};
}
示例6: Open
public void Open(string url, string protocol = null, string authToken = null)
{
try
{
if (_client != null)
Close();
NSUrlRequest req = new NSUrlRequest(new NSUrl(url));
if (!string.IsNullOrEmpty(authToken))
{
NSMutableUrlRequest mutableRequest = new NSMutableUrlRequest(new NSUrl(url));
mutableRequest["Authorization"] = authToken;
req = (NSUrlRequest)mutableRequest.Copy();
}
if (string.IsNullOrEmpty(protocol))
_client = new WebSocket(req);
else
_client = new WebSocket(req, new NSObject[] { new NSString(protocol) });
_client.ReceivedMessage += _client_ReceivedMessage;
_client.WebSocketClosed += _client_WebSocketClosed;
_client.WebSocketFailed += _client_WebSocketFailed;
_client.WebSocketOpened += _client_WebSocketOpened;
_client.Open();
}
catch (Exception ex)
{
OnError(ex.Message);
}
}
示例7: ShouldStartLoad
private bool ShouldStartLoad (NSUrlRequest request, UIWebViewNavigationType navigationType)
{
if (request.Url.AbsoluteString.StartsWith("app://resize"))
{
try
{
var size = WebView.EvaluateJavascript("size();");
if (size != null)
nfloat.TryParse(size, out _height);
if (HeightChanged != null)
HeightChanged(_height);
}
catch
{
}
return false;
}
if (!request.Url.AbsoluteString.StartsWith("file://"))
{
if (UrlRequested != null)
UrlRequested(request.Url.AbsoluteString);
return false;
}
return true;
}
示例8: DownloadImage
public void DownloadImage(string url)
{
indicatorView.StartAnimating();
NSUrlRequest request = new NSUrlRequest(new NSUrl(url));
new NSUrlConnection(request, new ConnectionDelegate(this), true);
}
示例9: ShouldStartLoad
public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
bool shouldStart = true;
string url = request.Url.ToString();
if (url.Contains("js-frame"))
{
shouldStart = false;
string pendingArgs = bridge.webBrowser.EvaluateJavascript("window.locationMessenger.pendingArg.toString();");
// Using JsonConvert.Deserialze<string[]> blows up under MonoTouch, so manually build the array of args instead
JArray argsJArray = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(pendingArgs);
string[] args = new string[argsJArray.Count];
for (int i = 0; i < argsJArray.Count; i++)
args[i] = (string)argsJArray[i];
if (args[0] == "HandleScriptPropertyChanged")
{
if (args.Length == 3)
bridge.HandleScriptPropertyChanged(args[1], args[2], null);
else
bridge.HandleScriptPropertyChanged(args[1], args[2], args[3]);
}
else if (args[0] == "InvokeViewModelIndexMethod")
bridge.InvokeViewModelMethod(args[1], args[2], args[3]);
else if (args[0] == "InvokeViewModelMethod")
bridge.InvokeViewModelMethod(args[1], args[2]);
else if (args[0] == "HandleDocumentReady")
bridge.HandleDocumentReady();
else if (args[0] == "HostLog")
bridge.HostLog(args[1]);
else
SpinnakerConfiguration.CurrentConfig.Log(SpinnakerLogLevel.Error,"Ignoring unrecognized call from javascript for [" + args[0] + "] - this means that javascript in the view is trying to reach the host but with bad arguments");
}
return shouldStart;
}
示例10: CachedResponseForRequest
public override NSCachedUrlResponse CachedResponseForRequest (NSUrlRequest request)
{
var uri = (Uri) request.Url;
int index;
if ((index = related.IndexOf (uri)) != -1) {
var part = related[index] as MimePart;
if (part != null) {
var mimeType = part.ContentType.MimeType;
var charset = part.ContentType.Charset;
NSUrlResponse response;
NSData data;
using (var content = part.ContentObject.Open ())
data = NSData.FromStream (content);
response = new NSUrlResponse (request.Url, mimeType, (int) data.Length, charset);
return new NSCachedUrlResponse (response, data);
}
}
return base.CachedResponseForRequest (request);
}
示例11: AudioSelected
public static UIViewController AudioSelected(ApiNode apiNode)
{
var url = apiNode["videoSrc1"];
if (apiNode["contentNode"] != null)
{
url = apiNode[apiNode["contentNode"]];
}
//var videoController = new UIVideoController(url);
//videoController.NavigationItem.Title = apiNode.Title;
//return videoController;
var vc = new UIViewController();
var webView = new UIWebView(UIScreen.MainScreen.Bounds)
{
BackgroundColor = UIColor.White,
ScalesPageToFit = true,
AutoresizingMask = UIViewAutoresizing.All
};
var request = new NSUrlRequest(new NSUrl(url), NSUrlRequestCachePolicy.UseProtocolCachePolicy, 60);
webView.LoadRequest(request);
vc.NavigationItem.Title = apiNode.Title;
vc.View.AutosizesSubviews = true;
vc.View.AddSubview(webView);
return vc;
}
示例12: ViewWillAppear
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
var urlRequest = new NSUrlRequest (new NSUrl (START_URL));
_webView.LoadRequest (urlRequest);
}
示例13: HandleShouldStartLoad
bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
// If the URL is not our own custom scheme, just let the webView load the URL as usual
const string scheme = "hybrid:";
if (request.Url.Scheme != scheme.Replace (":", ""))
return true;
// This handler will treat everything between the protocol and "?"
// as the method name. The querystring has all of the parameters.
var resources = request.Url.ResourceSpecifier.Split ('?');
var method = resources [0];
var parameters = System.Web.HttpUtility.ParseQueryString (resources [1]);
if (method == "UpdateLabel") {
var textbox = parameters ["textbox"];
// Add some text to our string here so that we know something
// happened on the native part of the round trip.
var prepended = string.Format ("C# says: {0}", textbox);
// Build some javascript using the C#-modified result
var js = string.Format ("SetLabelText('{0}');", prepended);
webView.EvaluateJavascript (js);
}
return false;
}
示例14: HandleShouldStartLoad
bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
// If the URL is not our own custom scheme, just let the webView load the URL as usual
var scheme = "app:";
if (request.Url.Scheme != scheme.Replace(":", ""))
return true;
var resources = request.Url.ResourceSpecifier.Split('?');
var method = resources[0];
if (method == "QR")
{
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
scanner.Scan().ContinueWith(result => {
if (result != null){
var code = result.Result.Text;
this.InvokeOnMainThread(new NSAction(() => webView.LoadRequest(new NSUrlRequest(new NSUrl(MainUrl + "code?value=" + code)))));
}
});
}
return false;
}
示例15: DownloadUsingNSUrlRequest
void DownloadUsingNSUrlRequest (object sender, EventArgs e)
{
var downloadedDelegate = new CustomDelegate(this);
var req = new NSUrlRequest(new NSUrl("http://ch3cooh.hatenablog.jp/"));
NSUrlConnection connection = new NSUrlConnection(req, downloadedDelegate);
connection.Start();
}