(GO) iOS development--to get rid of the disabled methods (continuous update)

Source: Internet
Author: User
Tags deprecated

iOS platform in the rapid development of various interfaces are constantly updated. With the release of IOS9, there are a number of old methods are not recommended, if you call these methods, the results of the operation is not a problem, but there will be a warning "***is deprecated:first deprecated in IOS 9.0-use *******". Like:

In actual project development, we must uphold the belief that every warning should be treated as an error and every warning should be resolved. You think, you run a project, even if the operation is successful, but there are dozens of, or even hundreds of yellow warning, the mood is not very bad? I will be in this blog combined with my development experience, the list of IOS9 not recommended methods, and replaced by Apple's latest recommended way. This blog post will be updated continuously.

1. "Pop-up prompt dialog box"

Before iOS9 we use Alertview to pop up the dialog, now we recommend using Alertcontroller, for this change, please refer to my other blog "iOS9 use the correct way to implement the box."

2. "Stringbyaddingpercentencodingwithallowedcharacters Replacement Stringbyaddingpercentescapesusingencoding"

This method is really very long ... We use this method to change the way strings are encoded. The most common place is to make an HTTP network request, the parameters of the sent link if with Chinese, then the first need to call this method to change the encoding mode to UTF8, because the server side is generally used UTF8 encoding. The function is the same for both implementations.

stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

Stringbyaddingpercentencodingwithallowedcharacters:[nscharacterset Urlqueryallowedcharacterset]];

3. "Nsurlsession Replacement Nsurlconnection"

Nsurlsession has gradually embarked on the stage of history. The recent use of [Nsurlconnection Sendasynchronousrequest] has been warned that is not recommended to use, then we will replace the Datataskwithrequest method in Nsurlsession.

  The following methods have been disabled;    nsoperationqueue *queue = [[Nsoperationqueue alloc] init];    [Nsurlconnection   sendasynchronousrequest:urlrequest   queue:queue   completionhandler:^ (NSURLResponse * Response,                       NSData *data,                       nserror *error) {          if ([data length] >0  &&         error = = nil) {       NSString *html = [[NSString alloc] Initwithdata:data                                              encoding:nsutf8stringencoding];       resault=[html copy];              NSLOG (@ returned server data =%@, HTML);     }     else if ([data length] = = 0 &&              error = = nil) {       NSLog (@Nothing was downloaded.);     }     else if (Error! = nil) {       NSLog (@ errors =%@, err);     }        }];

  It is recommended to use this method of request;  nsurlsession *session = [nsurlsession sharedsession];    __block  NSString *result = @;  Nsurlsessiondatatask *datatask = [Session datataskwithrequest:urlrequest completionhandler:^ (NSData * _Nullable data, Nsurlresponse * _nullable response, Nserror * _nullable error) {        if (!error) {      ///No error, return correct;      result = [[Nsstrin] G Alloc] Initwithdata:data encoding:nsutf8stringencoding];      NSLog (@ returned correctly:%@,result);          } else{      //error occurred;      NSLog (@ error message:%@,error);    }      }];      [Datatask resume];

(GO) iOS development--to get rid of the disabled methods (continuous update)

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.