IPhone programming-Basic Application of uiwebview

Source: Internet
Author: User
Tags pkcs12 pkcs7 rfc822 gtar

In iPhone applications, uiwebview is a good control for displaying website page content. Some basic usage records of this control are as follows.
The first step is to load the text type, such as HTML and TXT.
-(Void) loadhtmlstring :( nsstring *) string baseurl :( nsurl *) baseurl
That's all. The implementation code is as follows:
Nsbundle * bundle = [nsbundle mainbundle];
Nsstring * respath = [bundle resourcepath];
Nsstring * filepath = [respath stringbyappendingpathcomponent: @ "tt.html"];
[M_web loadhtmlstring: [nsstring stringwithcontentsoffile: filepath] baseurl: [nsurl fileurlwithpath: [bundle bundlepath];
However, there may be problems with text encoding display. For example, there may be problems with Chinese characters in the TXT file. Because the webpage cannot be parsed. However, you can set encoding for loading HTML pages. Of course, we have another loading method. Yes
-(Void) loaddata :( nsdata *) Data mimetype :( nsstring *) mimetype textencodingname :( nsstring *) encodingname baseurl :( nsurl *) baseurl
Method. The Code is as follows:
Nsbundle * bundle = [nsbundle mainbundle];
Nsdata * Data = [nsdata datawithcontentsoffile: [bundle pathforresource: @ "doc.txt" oftype: Nil];
[M_web loaddata: Data mimetype: @ "text/plain" textencodingname: @ "UTF-8" baseurl: [nsurl fileurlwithpath: [bundle bundlepath];
The parameter mimetype is used to set the file type for the file type can refer to the following: In addition, pay attention to the Internet digital distribution agency for the encoding name (IANA) encodingname UTF-8 and UTF-16 two types.
Of course, this method can also be used to load image resource audio files (in fact, other methods can also be processed, such as processing in HTML, here we need to directly operate on this type of file), but we must ensure that the file type is supported. In the special operation, you can set the file ratio as shown in Figure .png as follows:
Nsbundle * bundle = [nsbundle mainbundle];
Nsdata * Data = [nsdata datawithcontentsoffile: [bundle pathforresource: @ "appiconw.png" oftype: Nil];
[M_web loaddata: Data mimetype: @ "image/PNG" textencodingname: @ "UTF-8" baseurl: [nsurl fileurlwithpath: [bundle
Bundlepath];
Some files can be processed in the preceding two formats, such as audio files. Of course, this problem can still be solved. We can use another operation method.
-(Void) loadrequest :( nsurlrequest *) Request
This method enables you to play audio files. This operation can also be performed on text files. However, you must consider encoding. The procedure is as follows:
Nsstring * STR = [[nsbundle mainbundle] pathforresource: @ "aa.mp3" oftype: Nil];
Nsurlrequest * Req = [nsurlrequest requestwithurl: [nsurl fileurlwithpath: Str];
[M_web loadrequest: req];
The page is displayed as follows:
Nsstring * STR = [nsstring stringwithformat: @ "http://www.baidu.com"];
Nsurlrequest * Req = [nsurlrequest requestwithurl: [nsurl urlwithstring: Str];
[M_web loadrequest: req];
Note that the website Protocol cannot be omitted or the network data cannot be read. For example, the http://www.baidu.com to www.baidu.com operation is not successful.
For uiwebview operations, we usually need to pay attention to the processing of memory problems when exiting. For example, when parsing network data, we should call
-(Void) stoploading
To stop parsing the uiwebview data. In particular, it is very important to use a proxy or thread for operations. Otherwise, the parsed data may be sent to a released object.
I will not introduce other operations of uiwebview.
Appendix: For MIME types, see the following (of course some types are not supported ):
List of MIME types arranged by content type
Type/subtype
Extension
Application/envoy
Evy
Application/fractals
Fif
Application/futuresplash
SPL
Application/HTA
HTA
Application/Internet-property-stream
Acx
Application/mac-binhex40
Hqx
Application/MSWord
Doc
Application/MSWord
Dot
Application/octet-stream
*
Application/octet-stream
Bin
Application/octet-stream
Class
Application/octet-stream
DMS
Application/octet-stream
EXE
Application/octet-stream
Lha
Application/octet-stream
Lzh
Application/ODA
ODA
Application/olescript
Axs
Application/PDF
PDF
Application/pics-Rules
PRF
Application/pkcs10
P10
Application/pkix-CRL
CRL
Application/postscript
AI
Application/postscript
EPS
Application/postscript
PS
Application/RTF
RTF
Application/set-payment-Initiation
Setpay
Application/set-registration-Initiation
Setreg
Application/vnd. MS-Excel
Xla
Application/vnd. MS-Excel
Xlc
Application/vnd. MS-Excel
XLM
Application/vnd. MS-Excel
Xls
Application/vnd. MS-Excel
Xlt
Application/vnd. MS-Excel
Xlw
Application/vnd. MS-Outlook
MSG
Application/vnd. MS-pkicertstore
SST
Application/vnd. MS-pkiseccat
Cat
Application/vnd. MS-pkistl
STL
Application/vnd. MS-PowerPoint
Pot
Application/vnd. MS-PowerPoint
PPS
Application/vnd. MS-PowerPoint
PPT
Application/vnd. MS-Project
MPP
Application/vnd. MS-Works
Wcm
Application/vnd. MS-Works
Wdb
Application/vnd. MS-Works
Wks
Application/vnd. MS-Works
WPS
Application/WinHlp
HLP
Application/X-bcpio
Bcpio
Application/X-CDF
CDF
Application/X-compress
Z
Application/X-compressed
Tgz
Application/X-cpio
Cpio
Application/X-CSH
CSH
Application/X-Director
DCR
Application/X-Director
Dir
Application/X-Director
DxR
Application/X-DVI
DVI
Application/X-gtar
Gtar
Application/X-Gzip
GZ
Application/X-HDF
HDF
Application/X-Internet-signup
INS
Application/X-Internet-signup
ISP
Application/X-iPhone
III
Application/X-Javascript
JS
Application/X-latex
Latex
Application/X-msaccess
MDB
Application/X-mscardfile
CRD
Application/X-msclip
CLP
Application/X-msdownload
DLL
Application/X-msmediaview
M13
Application/X-msmediaview
M14
Application/X-msmediaview
MVB
Application/X-msmetafile
WMF
Application/X-msmoney
Mny
Application/X-mspublisher
Pub
Application/X-msschedule
SCD
Application/X-msterminal
TRM
Application/X-mswrite
WRI
Application/X-netcdf
CDF
Application/X-netcdf
NC
Application/X-perfmon
PMA
Application/X-perfmon
PMC
Application/X-perfmon
PML
Application/X-perfmon
PMR
Application/X-perfmon
PMW
Application/x-pkcs12
P12
Application/x-pkcs12
Pfx
Application/x-pkcs7-certificates
P7b
Application/x-pkcs7-certificates
SPC
Application/x-pkcs7-certreqresp
P7r
Application/x-pkcs7-mime
P7c
Application/x-pkcs7-mime
P7m
Application/x-pkcs7-signature
P7s
Application/X-SH
Sh
Application/X-shar
Shar
Application/X-Shockwave-flash
SWF
Application/X-stuffit
Sit
Application/x-sv4cpio
Sv4cpio
Application/x-sv4crc
Sv4crc
Application/X-Tar
Tar
Application/X-tcl
TCL
Application/X-Tex
Tex
Application/X-texinfo
Texi
Application/X-texinfo
Texinfo
Application/X-troff
Roff
Application/X-troff
T
Application/X-troff
Tr
Application/X-troff-man
Man
Application/X-troff-me
Me
Application/X-troff-MS
MS
Application/X-USTAR
USTAR
Application/X-WAIS-Source
SRC
Application/x-x509-ca-cert
CER
Application/x-x509-ca-cert
CRT
Application/x-x509-ca-cert
Der
Application/ynd. MS-pkipko
PKO
Application/zip
Zip
Audio/basic
Au
Audio/basic
SND
Audio/Mid
Mid
Audio/Mid
RMI
Audio/MPEG
MP3
Audio/X-AIFF
AIF
Audio/X-AIFF
Aifc
Audio/X-AIFF
AIFF
Audio/X-mpegurl
M3U
Audio/X-PN-RealAudio
RA
Audio/X-PN-RealAudio
Ram
Audio/X-WAV
Wav
Image/BMP
BMP
Image/cis-COD
COD
Image/GIF
GIF
Image/IEF
IEF
Image/JPEG
Jpe
Image/JPEG
JPEG
Image/JPEG
JPG
Image/pipeg
Jfif
Image/SVG + XML
SVG
Image/tiff
TIF
Image/tiff
Tiff
Image/X-CMU-raster
Ras
Image/X-cmx
Cmx
Image/X-icon
ICO
Image/X-portable-anymap
PNM
Image/X-portable-bitmap
PBM
Image/X-portable-graymap
PGM
Image/X-portable-pixmap
Ppm
Image/X-RGB
RGB
Image/X-xbitmap
Xbm
Image/X-xpixmap
XPM
Image/X-xwindowdump
Xwd
Message/rfc822
MHT
Message/rfc822
MHTML
Message/rfc822
NWS
Text/CSS
CSS
Text/h323
323
Text/html
Htm
Text/html
Html
Text/html
STM
Text/iuls
ULS
Text/plain
Bas
Text/plain
C
Text/plain
H
Text/plain
Txt
Text/richtext
RTX
Text/scriptlet
SCT
Text/TAB-separated-Values
TSV
Text/webviewhtml
HtT
Text/X-component
HTC
Text/X-setext
Etx
Text/X-vCard
VCF
Video/MPEG
MP2
Video/MPEG
MPa
Video/MPEG
MPE
Video/MPEG
MPEG
Video/MPEG
MPG
Video/MPEG
MPV2
Video/QuickTime
MoV
Video/QuickTime
Qt
Video/X-la-ASF
LSF
Video/X-la-ASF
LSX
Video/X-MS-ASF
ASF
Video/X-MS-ASF
ASR
Video/X-MS-ASF
ASX
Video/X-msvideo
Avi
Video/X-SGI-movie
Movie
X-World/X-Fig
FLR
X-World/X-Fig
Fig
X-World/X-Fig
WRL
X-World/X-Fig
Wrz
X-World/X-Fig
Xaf
X-World/X-Fig
XOF
=

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.