iOS uiapplication simple to use

Source: Internet
Author: User

Each app has and has only one UIApplication object, which is obtained by invoking the Uiapplicationmain method when the program starts. can be obtained by sharedapplication method.

The primary task of the UIApplication object is to handle the processing path of the user event, such as distributing a uievent to another object to handle. The UIApplication object holds numerous UIWindow objects, so you can organize your app's presentation. UIApplication objects can also handle resources, such as through OpenURL: Opening a mailbox client or setting up an interface.

Get UIApplication Object

[uiapplication sharedapplication]

Get Uiapplicationdelegate Object

[[UIApplication Sharedapplication] delegate]

Get UIWindow Object

[[UIApplication sharedapplication] windows];   UIWindow array [[UIApplication sharedapplication] Keywindow]; The UIWindow object in the UIWindow array that last called the Makekeyandvisible method

Control and Process Uievent

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{//Distributing an event to another object to handle    [[UIApplication sharedapplication] sendaction: @selector (action:forevent:) To:[customhandler Sharedcustomhandler] From:self forevent:event];}
[[UIApplication sharedapplication] beginignoringinteractionevents]; Start Ignoring event//... Middle call animation and other operations [[UIApplication Sharedapplication] endignoringinteractionevents];   End Ignore Event
[UIApplication sharedapplication].applicationsupportsshaketoedit = YES;  Does shaking have undo or redo action

Open a URL resource

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]];//Open the Settings screen

Configuring notification Settings

uiusernotificationtype types = Uiusernotificationtypebadge | Uiusernotificationtypesound | Uiusernotificationtypealert;

Uiusernotificationsettings  *mysettings  = [uiusernotificationsettings settingsfortypes:types categories: NIL]; [[UIApplication sharedapplication] registerusernotificationsettings:mysettings]; Registering Remote push notifications
[[uiapplication Sharedapplication] registerforremotenotifications];//registration [[UIApplication sharedApplication] unregisterforremotenotifications];//logoff
    NSDate *date = [NSDate datewithtimeintervalsincenow:10];    Uilocalnotification *localnotif = [[Uilocalnotification alloc] init];    Localnotif.firedate = date;  Time    localnotif.timezone = [Nstimezone localtimezone];//time zone    localnotif.repeatinterval = Nscalendarunitminute ; Interval    localnotif.soundname = uilocalnotificationdefaultsoundname;//sound    localnotif.alertbody = @ "Local Test";   Notification content    Localnotif.applicationiconbadgenumber = 1;  Digital indicator    Localnotif.userinfo = @{@ "key": @ "Test"};    Info    [[uiapplication sharedapplication] schedulelocalnotification:localnotif];//Registration Notice
    [[UIApplication sharedapplication] presentlocalnotificationnow:localnotif]; immediately notify    [[UIApplication sharedapplication] cancelalllocalnotifications];//Cancel all Notifications    [[UIApplication Sharedapplication] cancellocalnotification:localnotif]; Cancel a specific notification        nsarray *arr = [[UIApplication sharedapplication] scheduledlocalnotifications];  All the Notifications

Background Run related

[[UIApplication sharedapplication] applicationstate];//app State

    [[UIApplication sharedapplication] setminimumbackgroundfetchinterval:3600]; Set the background run time    nstimeinterval remaintime = [[UIApplication sharedapplication] backgroundtimeremaining];//app Background run time    NSLog (@ "remaintime =%f", remaintime);    int state = [[UIApplication sharedapplication] backgroundrefreshstatus]; The status of the background refresh    NSLog (@ "state =%d");    [[UIApplication sharedapplication] beginbackgroundtaskwithname:@ "TaskOne" expirationhandler:^{    }];    [[UIApplication sharedapplication] beginbackgroundtaskwithexpirationhandler:^{     }];    [[UIApplication sharedapplication] endbackgroundtask:1];

remote control-related

[[UIApplication sharedapplication] beginreceivingremotecontrolevents];

    [[UIApplication sharedapplication] endreceivingremotecontrolevents];

Idle Timer of the system

[UIApplication sharedapplication].idletimerdisabled = YES; Don't let your phone sleep

App Style

Hide Status bar

    [[UIApplication sharedApplication] Setstatusbarhidden:yes];

 [[UIApplication sharedapplication] Setstatusbarhidden:yes withanimation:uistatusbaranimationslide]; Set the style of the status bar [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstyledefault]; [[UIApplication sharedapplication] statusbarstyle]; Frame of the status bar [[UIApplication sharedapplication] statusbarframe]; Whether the network is visible [[UIApplication sharedapplication] isnetworkactivityindicatorvisible]; Badge number [UIApplication sharedapplication].applicationiconbadgenumber = 2; The direction of the screen [[UIApplication sharedapplication] userinterfacelayoutdirection];

Set the orientation of the status bar

[[uiapplication sharedapplication] Setstatusbarorientation:uiinterfaceorientationlandscapeleft Animated:yes];

Data type

uibackgroundtaskidentifier:int

typedef enum:nsuinteger {   Uiremotenotificationtypenone    = 0,   uiremotenotificationtypebadge   = 1 < < 0,   uiremotenotificationtypesound   = 1 << 1,   uiremotenotificationtypealert   = 1 << 2,   uiremotenotificationtypenewsstandcontentavailability = 1 << 3} Uiremotenotificationtype;
typedef Enum:nsinteger {   Uistatusbarstyledefault,   uistatusbarstylelightcontent,      Uistatusbarstyleblacktranslucent,   uistatusbarstyleblackopaque} uistatusbarstyle;
typedef Enum:nsinteger {   Uistatusbaranimationnone,   Uistatusbaranimationfade,   Uistatusbaranimationslide,} uistatusbaranimation;
typedef enum:nsinteger  {   uiapplicationstateactive,   uiapplicationstateinactive,   Uiapplicationstatebackground} uiapplicationstate;
Const Uibackgroundtaskidentifier  uibackgroundtaskinvalid; const Nstimeinterval  uiminimumkeepalivetimeout;
typedef enum:nsuinteger  {   uibackgroundfetchresultnewdata,   uibackgroundfetchresultnodata,   uibackgroundfetchresultfailed} Uibackgroundfetchresult;
Const NSTIMEINTERVAL  uiapplicationbackgroundfetchintervalminimum; Const Nstimeinterval  Uiapplicationbackgroundfetchintervalnever;
typedef enum:nsuinteger  {   uibackgroundrefreshstatusrestricted,   uibackgroundrefreshstatusdenied,   uibackgroundrefreshstatusavailable} Uibackgroundrefreshstatus;
typedef enum:nsinteger  {   Uiinterfaceorientationunknown             = Uideviceorientationunknown,   Uiinterfaceorientationportrait            = uideviceorientationportrait,   Uiinterfaceorientationportraitupsidedown  = Uideviceorientationportraitupsidedown,   Uiinterfaceorientationlandscapeleft       = uideviceorientationlandscaperight,   Uiinterfaceorientationlandscaperight      = uideviceorientationlandscapeleft} uiinterfaceorientation;
typedef enum:nsinteger  {   uiuserinterfacelayoutdirectionlefttoright,   Uiuserinterfacelayoutdirectionrighttoleft,} uiuserinterfacelayoutdirection;
NSString *const  uiapplicationopensettingsurlstring;
NSString *const  Uiapplicationstatusbarorientationuserinfokey; NSString *const  Uiapplicationstatusbarframeuserinfokey;
NSString *const  Uicontentsizecategoryextrasmall; NSString *const  Uicontentsizecategorysmall; NSString *const  Uicontentsizecategorymedium; NSString *const  Uicontentsizecategorylarge; NSString *const  Uicontentsizecategoryextralarge; NSString *const  Uicontentsizecategoryextraextralarge; NSString *const  Uicontentsizecategoryextraextraextralarge;
NSString *const  Uicontentsizecategoryaccessibilitymedium; NSString *const  Uicontentsizecategoryaccessibilitylarge; NSString *const  Uicontentsizecategoryaccessibilityextralarge; NSString *const  Uicontentsizecategoryaccessibilityextraextralarge; NSString *const  Uicontentsizecategoryaccessibilityextraextraextralarge;
NSString *const  uiapplicationinvalidinterfaceorientationexception;

Notice

Uiapplicationbackgroundrefreshstatusdidchangenotification

Uiapplicationdidbecomeactivenotification

Uiapplicationdidchangestatusbarframenotification

Uiapplicationdidchangestatusbarorientationnotification

Uiapplicationdidenterbackgroundnotification

Uiapplicationdidfinishlaunchingnotification

Uiapplicationdidreceivememorywarningnotification

Uiapplicationprotecteddatadidbecomeavailable

Uiapplicationprotecteddatawillbecomeunavailable

Uiapplicationsignificanttimechangenotification

Uiapplicationuserdidtakescreenshotnotification

Uiapplicationwillchangestatusbarorientationnotification

Uiapplicationwillchangestatusbarframenotification

Uiapplicationwillenterforegroundnotification

Uiapplicationwillresignactivenotification

Uiapplicationwillterminatenotification

Uicontentsizecategorydidchangenotification

iOS uiapplication simple to use

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.