iOS Learning Notes (3) Single-Case mode application case

Source: Internet
Author: User

In the cocoa touch framework, there are uiapplication, Uiaccelerimeter, Nsuserdefaults, and Nsnotificationcenter singleton classes. In addition, although the Nsfilemanager and NSBundle classes are part of the cocoa framework, they can also be used in the Cocoa Touch Framework (cocoa, Nsfilemanager, Nsworkspace and NSApplication, etc.).

1.UIApplication

An instance of the UIApplication class provides an application's centralized control point to maintain the state of the application. The UIApplication instance is always assigned to the application delegate object (Uiapplicationdelegate), which responds to events such as low memory, app startup, background run, and app termination through application delegate objects.

The UIApplication class has a number of methods and properties, which are highlighted below.

· + Sharedapplication method. Methods for creating and obtaining uiapplication instances.

· The Idletimerdisabled property. Set and get the status of "Idle Time Forbidden". The default value of the Idletimedisabled property is no, which means that the system locks the screen by default. When Idletimerdisabled=yes, the "Idle Time Forbidden" State is not turned on and the screen is not locked. You need to be cautious about turning on this setting, which will make your app consume less power.

· -OpenURL: Method. You can open some of the built-in iOS apps, including opening your browser, opening Google Maps, making calls, sending text messages, and sending e-mails.

2.UIAccelerometer

The Singleton class, Uiaccelerometer, is also mentioned earlier, which accesses the gravity accelerometer hardware device to obtain real-time acceleration in the x-axis, y-axis, and z-axis direction of the device.

The + Sharedaccelerometer method is to create and obtain a shared method of the Uiaccelerometer instance.

Similar to UIApplication, Uiaccelerometer also has a corresponding delegate object whose delegate object is Uiaccelerometerdelegate. Uiaccelerometer assigns an instance to the delegate object Uiaccelerometerdelegate, and then the delegate object responds to the gravity accelerometer event.

3.NSUserDefaults

The Singleton class Nsuserdfaults can easily read application settings items.

The + Standarduserdefaults method is a static method that creates and obtains a nsuserdefaults instance.

4.NSNotificationCenter

The Singleton class Nsnotificationcenter provides the information broadcast notification, which uses the observer mode notification mechanism.

The + Defaultcenter method is to create and obtain a shared method of the Nsnotificationcenter instance.

5.NSFileManager

Nsfilemanager provides a common operation to access the file system to locate, create, and copy files and folders. After iOS 5 and Mac OS X v10.7, it can also manage data stored on icloud.

The + Defaultmanager method is the way to create and obtain an Nsfilemanager instance. In addition to this method, you can also use the instance construction method-init when creating a Nsfilemanager object. The two methods are quite different, and the + Defaultmanager method always returns the same Nsfilemanager object, but if you want to use a delegate (nsfilemanagerdelegate) to complete file-based operations and accept notifications, you should use- The Init method creates a new instance instead of using the shared object.

6.NSBundle

NSBundle provides the ability to dynamically load (or unload) executable code, locate resource files, and localize resources, Access file systems, and more.

The + Mainbundle method is to create and obtain a shared method of the NSBundle instance.

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.