Call in iOS, open URLs, send emails, send text messages, etc.

Source: Internet
Author: User

Common small functions

Introduction to Small functions

Many of the small features in iOS are simple, with a few lines of code, such as calling, opening URLs, sending emails, texting, etc.

Call-Method 1

The simplest and most straightforward way: jump directly to the dial-up interface

Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"];

[[UIApplication sharedapplication] openurl:url];

Disadvantages

After the call, will not automatically return to the original application, directly in the Call log interface

Call-Method 2

Before dialing, the box asks the user whether to dial or not and automatically returns to the original application after dialing out.

Nsurl *url = [Nsurl urlwithstring:@ "telprompt://10010"];

[[UIApplication sharedapplication] openurl:url];

Disadvantages

Because it is a private API, it may not be audited by

Call-Method 3

Create a UIWebView to load the URL and automatically go back to the original app when you're finished dialing

if (_webview = = nil) {

_webview = [[UIWebView alloc] Initwithframe:cgrectzero];

}

[_webview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@ "tel://10010"]];

Note: This webview must not be added to the interface, or it will block other interfaces

Texting-Method 1

Jump directly to the text messaging interface, but cannot specify the text message content, and can not automatically return to the original application

Nsurl *url = [Nsurl urlwithstring:@ "sms://10010"];

[[UIApplication sharedapplication] openurl:url];

Texting-Method 2

If you want to specify a text message, you have to use the MESSAGEUI framework

Include primary header file

#import <MessageUI/MessageUI.h>

Display the controller that sent the text message

Mfmessagecomposeviewcontroller *VC = [[Mfmessagecomposeviewcontroller alloc] init];

Set SMS Content

Vc.body = @ "Have you eaten yet?" ";

Set up a recipient list

vc.recipients = @[@ "10010", @ "02010010"];

Set up Proxy

Vc.messagecomposedelegate = self;

Display Controller

[Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];

Texting-Method 2

Proxy method, when the SMS interface is closed when the call, after the end will automatically return to the original application

-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result

{

Close the SMS interface

[Controller Dismissviewcontrolleranimated:yes Completion:nil];

if (result = = messagecomposeresultcancelled) {

NSLog (@ "Cancel send");

} else if (result = = Messagecomposeresultsent) {

NSLog (@ "already issued");

} else {

NSLog (@ "send failed");

}

}

Send e-mail-Method 1

With your own mail client, will not automatically return to the original application after sending the message

Nsurl *url = [Nsurl urlwithstring:@ "mailto://[email protected]";

[[UIApplication sharedapplication] openurl:url];

Send e-mail-Method 2

The 2nd method of texting is similar, except that the controller class name is: Mfmailcomposeviewcontroller

Assuming that the message is sent as shown in the image on the right, the code implementation looks at the notes

Send e-mail-Method 2

The proxy method callback after the message is sent, will automatically return to the original application after sending

-(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (NSERROR *) error

{

Close the Mail interface

[Controller Dismissviewcontrolleranimated:yes Completion:nil];

if (result = = mfmailcomposeresultcancelled) {

NSLog (@ "Cancel send");

} else if (result = = Mfmailcomposeresultsent) {

NSLog (@ "already issued");

} else {

NSLog (@ "send failed");

}

}

Open Other Common Files

If you want to open some common files, such as HTML, TXT, PDF, PPT, etc., you can use UIWebView open

Just tell the URL of the UIWebView file to

As for opening a remote shared resource, such as the HTTP protocol, you can also call the system's own Safari browser:

Nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"];

[[UIApplication sharedapplication] openurl:url];

Inter-app Jump

Sometimes it is necessary to open other applications in this application, such as jumping from A to B application

First, the B application has its own URL address (configured in info.plist)

b The URL address of the app is: mj://ios.itcast.cn

Then use UIApplication in a application to complete the jump

Nsurl *url = [Nsurl urlwithstring:@ "mj://ios.itcast.cn"];

[[UIApplication sharedapplication] openurl:url];

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 writing a review by the user himself

How to jump to AppStore and show your app

Ø Method 1

NSString *appid = @ "444934666";

NSString *str = [NSString stringWithFormat:

@ "itms-apps://ax.itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?type=purple+software& id=%@ ", AppID];

[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];

Ø Method 2

NSString *str = [NSString stringWithFormat:

@ "itms-apps://itunes.apple.com/cn/app/id%@?mt=8", AppID];

[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];

Real-Machine debugging

The main steps of real machine debugging

1. Login to Developer Home 2. Generate a CER certificate: A CER is a certificate file associated with a computer that allows the computer to function with real-machine debugging 3. Add App ID: What apps are you debugging? 4. Registering a real-machine device: Which device needs to do real-machine debugging? 5. Generate a Mobileprovision file: Combine 2, 3, 4 to generate a mobile phone rule file 6. Import cer, mobileprovision file

will eventually get 2 files

Øcer file: Let the computer with the function of real machine debugging Ømobileprovision file: Which device, which app, which computer needs to do the real machine debugging?

Step 01 of real-Machine debugging-Login to developer homepage

Login to Developer homepage

Https://developer.apple.com/membercenter/index.action

Management Certificate (Prerequisite: Spend 99$ or 299$ to join the developer program)

Step 02 of real-Machine debugging-Generate a CER certificate

Add a CER certificate

Step 02 of real-Machine debugging-Generate a CER certificate

Generate CER signature request files with Keychain

Step 02 of real-Machine debugging-Generate a CER certificate

Select a CER signature request file to generate and download a CER certificate

Step 03 of real-Machine debugging-add app ID

Add App ID

Step 04 of real-Machine debugging-registering a real-machine device

Adding a real-machine device

Step 04 of real-Machine debugging-registering a real-machine device

Use Xcode to view the unique identity of a real device (plug in a USB cable)

Step 04 of real-Machine debugging-registering a real-machine device

Fill in the device name and unique identification

Step 05 of real-machine debugging-Generate a Mobileprovision file

Add mobileprovision File

Step 05 of real-machine debugging-Generate a Mobileprovision file

Select App ID

Step 05 of real-machine debugging-Generate a Mobileprovision file

Fill in the Mobileprovision file name

Step 06 of real-Machine debugging-Import CER, mobileprovision file

After a few steps, you've got 2 files.

Step 06 of real-Machine debugging-Import CER, mobileprovision file

Open any program, select the real machine set, click to run (the first run will appear on the right image)

Replace the old debug certificate

Call in iOS, open URLs, send emails, send text messages, etc.

Related Article

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.