IOS Development notes (2)

Source: Internet
Author: User
Document directory
  • How to send emails in iPhone applications

Multi-thread nsinvocationoperation

Multi-threaded programming is the best way to prevent the main thread from being congested and increase the running efficiency. The original multi-threaded method has many problems, including thread locking. In cocoa, Apple provides the nsoperation class and an excellent multi-threaded programming method.

This section describes the subset of nsoperation and nsinvocationoperation of the simple method:

@ Implementation mycustomclass-(void) launchtaskwithdata :( ID) Data {// create an nsinvocationoperation object and initialize it to the method // here, the value after the selector parameter is the method (function, method) You want to run in another thread // here, the value after the object is the data nsinvocationoperation * theop = [[nsinvocationoperation alloc] initwithtarget: Self selector: @ selector (mytaskmethod :) object: Data] to be passed to the preceding method. // Add the operation "operation" we created to the shared queue of the local program (the method will be executed immediately after the operation is added) // In more cases, we will create our own "operation" queue [[myappdelegate implements doperationqueue] addoperation: theop];} // This is the "method" that actually runs in another thread-(void) mytaskmethod :( ID) Data {// perform the task .} @ end

An nsoperationqueue operation queue is equivalent to a thread manager rather than a thread. Because you can set the number of threads that can run in parallel in this thread manager. The following describes how to create and initialize an operation queue:

@ Interface myviewcontroller: uiviewcontroller {nsoperationqueue * operationqueue; // declare the queue in the header file} @ end @ implementation myviewcontroller-(ID) Init {self = [Super init]; if (Self) {operationqueue = [[nsoperationqueue alloc] init]; // initialize the operation queue [operationqueue setmaxconcurrentoperationcount: 1]; // This limits the queue to run only one thread at a time. // This queue can already use} return self;}-(void) dealloc {[operationqueue release]; // as Alan often said, We are Cheng Ordered good citizens, need to release memory! [Super dealloc];} @ end

After a brief introduction, we can find that this method is very simple. In many cases, multithreading is only used to prevent main thread congestion, and nsinvocationoperation is the simplest multi-threaded programming, which is often used in iPhone programming.

How to send emails in iPhone applications

From: http://blog.csdn.net/iefreer/archive/2009/10/28/4740517.aspx

3.0 use mailto URL before, but will exit the current application

After 3.0, Apple provided the messageui framework to implement the mail sending function in our application. For code demonstration, see:

Https://developer.apple.com/iphone/library/samplecode/MailComposer/index.html

You can add attachments and send emails in HTML format.

If you want to add a URL in a mail, such as: http://ditu.at/tinyurl

It can be encoded as follows:

// Fill out the email body text

Nsstring * emailbody = [[nsstring alloc] init];

Nsarray * arsubviews = [lateral view subviews];

Uitextfield * tvmessage = [arsubviews objectatindex: 4];

Emailbody = [nsstring stringwithformat: @ "% @, % @ <a href = '% @' >%@ </a>", tvmessage. text, nslocalizedstring (@ "for_details ",@""),

[Self. tinyurllist objectatindex: 0], [self. tinyurllist objectatindex: 0];

If you want to provide a link to your app store in the email, you can encode it as follows:

Nsstring * pagelink = @ "http://mugunthkumar.com/yourapp ";

Nsstring * ituneslink = @ "http: // link-to-yourapp ";

Nsstring * emailbody =

[Nsstring stringwithformat: @ "% @ \ n

Remember to use HTML format:

[Mailpicker setmessagebody: emailbody ishtml: Yes];

[Self presentmodalviewcontroller: mailpicker animated: Yes];

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.