iOS app development has many very useful small functions, the implementation of these small features is very simple, this article summarizes these small features for the memo.
1. Implementation of the Call function
There are several ways to make phone calls, the best of which is as follows:
Use UIWebView call if (_webview = = nil) { //webview do not need to display, just to implement the call function _webview = [[UIWebView alloc] Initwithframe:cgrectzero]; } [_webview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@ "tel://10010"]];
2. The realization of texting function
There are many ways to implement texting, but the following are the best:
2. Functions encapsulated with MESSAGEUI framework mfmessagecomposeviewcontroller *MESSAGEVC = [[Mfmessagecomposeviewcontroller alloc] Init ]; Messagevc.body = @ "Have you eaten?" "; messagevc.recipients = @[@ "10010", @ "10086"]; Set proxy messagevc.messagecomposedelegate = self;[ Self PRESENTVIEWCONTROLLER:MESSAGEVC animated:yes completion:nil]; #pragma mask mfmessagecomposeviewcontrollerdelegate-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) Controller didfinishwithresult: (messagecomposeresult) result{ //Turn off SMS interface [controller Dismissviewcontrolleranimated:yes Completion:nil]; if (result = = messagecomposeresultcancelled) { NSLog (@ "Cancel send"); } else if (result = = messagecomposeresultsent) { NSLog (@ "sent successfully"); } else{ NSLog (@ "send Failed");} }
3. The implementation of the E-mail function
There are several ways to implement the E-mail feature, which is recommended in the following ways:
Features encapsulated with MESSAGEUI framework Mfmailcomposeviewcontroller *MAILVC = [[Mfmailcomposeviewcontroller alloc] init]; Set the message subject [MAILVC setsubject:@ meeting]];//set up the message content [MAILVC setmessagebody:@ "You're going to eat Xiang this afternoon!" [Ishtml:no]; Set recipient list [MAILVC settorecipients:@[@ "[email protected]"]; Set up cc list [MAILVC setccrecipients:@[@ "[email protected]"]; Set up a BCC list [MAILVC setbccrecipients:@[@ "[email protected]"]; Add a drawing (a picture) UIImage *image = [UIImage imagenamed:@ "Aaa.png"]; Compress picture NSData *data = uiimagepngrepresentation (image); [MAILVC addattachmentdata:data mimetype:@ "image/png" filename:@ "Aaa.png"]; Set proxy mailvc.mailcomposedelegate = self; [Self PRESENTVIEWCONTROLLER:MAILVC animated:yes completion:nil]; #pragma mask mfmailcomposeviewcontrollerdelegate-( void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (NSERROR *) error{[controller Dismissviewcontrolleranimated:yes Completion:nil]; if (result = = mfmailcomposeresultcancelled) {NSLog (@ "Cancel send"); }else if (result = = Mfmailcomposeresultsent) {NSLog (@ "send success"); }else{NSLog (@ "send failed"); }}
4. Apply scoring function
The following code is used to implement the app scoring feature:
Get the App id nsstring *appid = @ "123456"; NSString *str = [NSString stringwithformat:@ "itms-apps://ituns.apple.com/app/id%@?mt=8", AppID]; Nsurl *url = [Nsurl urlwithstring:str]; [[UIApplication sharedapplication] openurl:url];
5. Open a frequently used file
In iOS development, if you want to open some common files, such as Html/txt/pdf/ppt, you can choose to open with UIWebView, just tell UIWebView URL, if you want to open a remote shared resources, such as the HTTP protocol resources, You can also call the system's own Safari browser
Nsurl *url = [Nsurl urlwithstring:@ "http://m.baidu.com"]; [[UIApplication sharedapplication] openurl:url];
6. Associating to other applications
Sometimes, you need to open other app B in the current app A, and you need to go through the following two steps:
1.) First, the B application has its own URL address (configured in info.plist)
The URL address for the configured B app is: mj://ios.itcast.cn
2.) then use UIApplication in a application to complete the jump
Nsurl *url = [Nsurl urlwithstring:@ "mj://ios.itcast.cn"]; [[UIApplication sharedapplication] openurl:url];
demo:http://download.csdn.net/detail/luozhonglan/8381037
Implementation of iOS common small features