Some questions about the SDK version in the 31-day App Tutorial sample (GO)

Source: Internet
Author: User

Since the well-known 31-day case tutorial abroad is older, the official API is 2.X in 2008, so there are more or less compile warnings and error messages after the current xcode3-4. You must do some code changes to fit the iOS version to successfully compile the pass.

Day1:minutes to Midnight

nsdate* now = [NSDate Date];
-[Now Datewithcalendarformat:nil Timezone:nil] hourofday];
-[Now Datewithcalendarformat:nil Timezone:nil] minuteofhour];
-[Now Datewithcalendarformat:nil Timezone:nil] secondofminute];

Here Datewithcalendarformat: After the official API 2.2.1, there will be a warning error. In xcode3.x and later versions, the following modifications are required to compile the pass:

 Nscalendar *calendar = [[Nscalendar alloc] Initwithcalendaridentifier: Nsgregoriancalendar]; Nsinteger unitflags  = Nsyearcalendarunit | Nsmonthcalendarunit | Nsdaycalendarunit | Nshourcalendarunit | Nsminutecalendarunit |  Nssecondcalendarunit; NSDate  *date = [NSDate Date]; Nsdatecomponents  *comps = [calendar components:unitflags fromdate:date];  int  hour = 23 -  [comps hour];  int  min = 59 -  [comps minute];  int  sec = 59 -[comps second]; 

Day3:openurl
Statement: NSLog (Urltext); Generate warning Error: format string is not a string literal (potentially insecure)
Modified to: NSLog (@ "%@", Urltext);
Of course this sentence does not change, nsstring *urltext = [NSString stringwithformat:@ "http://maps.google.com.hk/maps?q=%@", AddressText];

Day4:what is My IP
For Get iphone native IP address, on iphone ios2. X can be obtained using the method call in the sample code:

Nshost  *myhost = [Nshost  currenthost];

NSString *ad = [myhost address];

However, after iOS 3.0, these methods become the Apple private API, at compile time will not find the error of this method declaration, the use of the private API submitted by the app will be reject. For this reason, it is recommended to use a custom IP address class file on the network. Relevant files are: IPAddress.h (http://iphonesdksnippets.com/post/2009/09/07/Get-IP-address-of-iPhone.aspx)

Reprint: http://www.cnblogs.com/lovecode/archive/2011/12/11/2283914.html

Some questions about the SDK version in the 31-day App Tutorial sample (GO)

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.