How to use NSRequest in Delphi XE4
2013-07-06 01:18
225 查看
//Demo How to use NSRequest..
procedure TiOSWebBrowserService.DoNavigate(const URL: string);
var
NewURL: string;
NSNewURL: NSURL;
NSNewURLRequest: NSURLRequest;
LPath: NSString;
LFilePath: string;
LDir, LFileName : string;
Bundle : Pointer;
begin
NewURL := URL;
if Pos('file://', URL) <> 0 then
begin
//extract the file name, the string after file://
NewURL := Copy(URL, length('file://') + 1, length(URL));
LDir := ExtractFileDir(NewURL);
LFileName := ExtractFileName(NewURL);
if LDir.IsEmpty then
Bundle := TNSBundle.OCClass.mainBundle
else
Bundle := TNSBundle.OCClass.bundleWithPath(NSSTR(LDir));
LPath := TNSBundle.Wrap(Bundle).pathForResource(NSSTR(LFileName), nil);
if Assigned(LPath) then
begin
LFilePath := UTF8ToString(LPath.UTF8String);
if not FileExists(LFilePath) then
raise EFileNotFoundException.Create(SFileNotFound);
NSNewURL := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(LPath));
end;
end
else
begin
if Pos('http', URL) = 0 then
Insert('http://', NewURL, 0);
NSNewURL := TNSUrl.Wrap(TNSUrl.OCClass.URLWithString(NSStr(NewURL)));
end;
NSNewURLRequest:= TNSURLRequest.Wrap(TNSURLRequest.OCClass.requestWithURL(NSNewURL));
FWebView.loadRequest(NSNewURLRequest);
FWebView.setFrame(CGRectFromRect(RectF(0, 0, 1, 1)));
UpdateContentFromControl;
end;
//almost same with objective c style
ToCheck: customized tableview cell . color / bg / font/ in-app purchase subscribe
procedure TiOSWebBrowserService.DoNavigate(const URL: string);
var
NewURL: string;
NSNewURL: NSURL;
NSNewURLRequest: NSURLRequest;
LPath: NSString;
LFilePath: string;
LDir, LFileName : string;
Bundle : Pointer;
begin
NewURL := URL;
if Pos('file://', URL) <> 0 then
begin
//extract the file name, the string after file://
NewURL := Copy(URL, length('file://') + 1, length(URL));
LDir := ExtractFileDir(NewURL);
LFileName := ExtractFileName(NewURL);
if LDir.IsEmpty then
Bundle := TNSBundle.OCClass.mainBundle
else
Bundle := TNSBundle.OCClass.bundleWithPath(NSSTR(LDir));
LPath := TNSBundle.Wrap(Bundle).pathForResource(NSSTR(LFileName), nil);
if Assigned(LPath) then
begin
LFilePath := UTF8ToString(LPath.UTF8String);
if not FileExists(LFilePath) then
raise EFileNotFoundException.Create(SFileNotFound);
NSNewURL := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(LPath));
end;
end
else
begin
if Pos('http', URL) = 0 then
Insert('http://', NewURL, 0);
NSNewURL := TNSUrl.Wrap(TNSUrl.OCClass.URLWithString(NSStr(NewURL)));
end;
NSNewURLRequest:= TNSURLRequest.Wrap(TNSURLRequest.OCClass.requestWithURL(NSNewURL));
FWebView.loadRequest(NSNewURLRequest);
FWebView.setFrame(CGRectFromRect(RectF(0, 0, 1, 1)));
UpdateContentFromControl;
end;
//almost same with objective c style
ToCheck: customized tableview cell . color / bg / font/ in-app purchase subscribe
相关文章推荐
- How to Use the Dynamic Link Library in C++ Linux (C++调用Delphi写的.so文件)
- How to create an XTR file from XML in Delphi XE4 using XML Mapper?(delphi中如何通过xmlmapper创建xtr文件)
- How to use forms in Tapestry 5.
- How to use Terminal in Vim
- How to use MathJax in Markdown
- How to use Session in MVC4
- How to use isInEditMode() to see layout with custom View in the editor
- How To Use DBLink In Oracle Forms 6i
- How to use Oracle Instant Client in Mac OS X Lion
- how to use Pointer in JNA.
- How to use a TControlCanvas in a component
- How To Use A Launchpad PPA (Add, Remove, Purge, Disable) In Ubuntu
- How to use FTP in Python
- How to use udev for Oracle ASM in Oracle Linux 5
- 如何在C++中使用VBScript(使用Qt)--How to use VBScript in C++ (Using Qt)
- 如何在python中使用*args,**kwargs (How to use *args and **kwargs in Python)
- How to use SSH Via HTTP Proxy using Corkscrew in Ubuntu
- how to use sqlserver2008 to search in files
- How to use lateral view explode() function in Hive (HIve 中的explode()函数使用)
- How To Use The New Multivalue Field In Access 2007/2010 Sunday, June 19th, 2011