<span id="Label3"></p>Often small features of iOS many small features are very simple, a few lines of code, such as phone calls, open urls, e-mail, texting and other calls method one (not adopted): before dialing the box asks the user whether dial, after dial can automatically return to the original application<pre><pre>Nsurl *url = [nsurl urlwithstring:<span style="color: #800000;">@ "</span><span style="color: #800000;">telprompt://10010</span><span style="color: #800000;">"</span><span style="color: #000000;">];[ [uiapplication sharedapplication] openurl:url];</span></pre></pre>Disadvantages<p><p>Because it is a private api, it may not be audited by</p></p><p><p>Method Two (recommended use):</p></p>Create a UIWebView to load the URL and automatically go back to the original app when You're finished dialing<pre><pre><span style="color: #0000ff;">if</span> (_webview = =<span style="color: #000000;"> Nil) {</span>=<span style="color: #000000;"> [[uiwebview alloc] initwithframe:cgrectzero];} [_webview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:</span><span style="color: #800000;">@ "</span><span style="color: #800000;">tel://10010</span> <span style="color: #800000;"> "</span>]]];</pre></pre><p><p>Note: <span style="color: #ff0000;">This webview must not be added to the interface,</span> or it will block other Interfaces.</p></p>Text message if you want to specify the content of the text, you have to use the Messageui framework, including the main header file<p><p>#import <MessageUI/MessageUI.h></p></p>Display the controller that sent the text message<pre>Mfmessagecomposeviewcontroller *VC =<span style="color: #000000;"><span style="color: #000000;">[[mfmessagecomposeviewcontroller alloc] init];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set SMS Content</span></span>Vc.body =<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">did you have dinner? </span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a recipient list</span></span>Vc.recipients = @[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">10010</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>,<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">02010010</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set up proxy</span></span>Vc.messagecomposedelegate =<span style="color: #000000;">self <span style="color: #000000;">;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Display Controller</span></span>[self PRESENTVIEWCONTROLLER:VC Animated:yes completion:nil];</pre><p><p>Proxy method, When the SMS interface is closed when the call, after the end will automatically return to the original application</p></p><pre>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Messagecomposeviewcontroller: (mfmessagecomposeviewcontroller *<span style="color: #000000;"><span style="color: #000000;">controller didfinishwithresult: (messagecomposeresult) result{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Close the SMS interface</span></span><span style="color: #000000;"><span style="color: #000000;">[controller Dismissviewcontrolleranimated:yes completion:nil]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(result = =<span style="color: #000000;"><span style="color: #000000;">Messagecomposeresultcancelled) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Cancel Send</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(result = =<span style="color: #000000;"><span style="color: #000000;">Messagecomposeresultsent) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">has been issued</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Send failed</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); }}</span></span></pre><p><p>of course, The texting method can only be dispatched in the real machine, if called in the simulator, will be abnormal, in the simulator, you can add judgment:</p></p><pre><pre><span style="color: #0000ff;">if</span> <span style="color: #0000ff;">return</span>;</pre></pre>E-mail with the 2nd way to send text messages, but the controller class name is Called: Mfmailcomposeviewcontroller<pre><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Cannot send mail</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(! [mfmailcomposeviewcontroller Cansendmail])<span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">; Mfmailcomposeviewcontroller</span></span>*VC =<span style="color: #000000;"><span style="color: #000000;">[[mfmailcomposeviewcontroller alloc] init];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set Message subject</span></span>[VC setsubject:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Conference</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up message content</span></span>[VC setmessagebody:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Let's have a meeting this afternoon.</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">ishtml:no];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a recipient list</span></span>[VC settorecipients:@[<span style="color: #800000;"><span style="color: #800000;">@ "1234</span></span><span style="color: #800000;"><span style="color: #800000;">@qq. com</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a CC person list</span></span>[VC setccrecipients:@[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a BCC list</span></span>[VC setbccrecipients:@[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Add an attachment (a picture)</span></span>UIImage *image = [UIImage imagenamed:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Lufy.jpeg</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; NSData</span></span>*data = UIImageJPEGRepresentation (image,<span style="color: #800080;"><span style="color: #800080;">0.5</span></span><span style="color: #000000;"><span style="color: #000000;">); [VC Addattachmentdata:data mimeType:</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">IMAGE/JEPG</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>FileName:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Lufy.jpeg</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set up proxy</span></span>Vc.mailcomposedelegate =<span style="color: #000000;">self <span style="color: #000000;">;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Display Controller</span></span>[self PRESENTVIEWCONTROLLER:VC Animated:yes completion:nil];</pre>The proxy method callback after the message is sent, will automatically return to the original application after sending<pre>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Mailcomposecontroller: (mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (nserror *<span style="color: #000000;"><span style="color: #000000;">) error{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Close the Mail interface</span></span><span style="color: #000000;"><span style="color: #000000;">[controller Dismissviewcontrolleranimated:yes completion:nil]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(result = =<span style="color: #000000;"><span style="color: #000000;">Mfmailcomposeresultcancelled) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Cancel Send</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(result = =<span style="color: #000000;"><span style="color: #000000;">Mfmailcomposeresultsent) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">has been issued</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Send failed</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); }}</span></span></pre>Open other common Files if you want to open some common files, such as html, txt, PDF, ppt, etc., You can use UIWebView open only to tell the UIWebView file URL can be opened a remote shared resources, such as the HTTP protocol, You can also call the System's own safari browser:<pre><pre>sURL *url = [nsurl urlwithstring:@ "http:<span style="color: #008000;">//</span><span style="color: #008000;">www.baidu.com"];</span> <span style="color: #000000;">[[uiapplication sharedapplication] openurl:url];</span></pre></pre>Inter-app Jump<p><p>Sometimes it is necessary to open other applications in this application, such as jumping from A to B application</p></p><p><p>first, the B application has its own URL address (configured in Info.plist)</p></p><p><p></p></p>The URL address of the B app is: mj://ios.itcast.cn then use uiapplication to complete the jump in a application<pre><pre>Nsurl *url = [nsurl urlwithstring:<span style="color: #800000;">@ "</span><span style="color: #800000;">mj://ios.itcast.cn</span><span style="color: #800000;">"</span><span style="color: #000000;">];[ [uiapplication sharedapplication] openurl:url];</span></pre></pre>App ratings to improve the user experience of your app, you often need to invite users to score Apps. App scoring is all about jumping to AppStore to show your app, and then the user writing a comment to jump to AppStore and show their app<pre><pre>NSString *str =<span style="color: #000000;"> [nsstring stringwithformat: </span><span style="color: #800000;">@ "</span><span style="color: #800000;">itms-apps://itunes.apple.com/cn/app/id%@? mt=8</span><span style="color: #800000;">"</span><span style="color: #000000;">, appid]; [[uiapplication sharedapplication] Openurl:[nsurl urlwithstring:str]];</span></pre></pre><p><p></p></p><p><p>Overview of IOS Common small features</p></p></span>
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