Methods that may be used in the Appdelegate file

Source: Internet
Author: User

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Override point for customization after application launch.

Todo:connect to Socket.io Server

Load Server Configuration

Load Advertisement

Enabling keyboard Manager

return YES;

}

-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {

NSLog (@ "Devicetoken:%@", Devicetoken);

NSString *strdev = [[[[Devicetoken description] Stringbyreplacingoccurrencesofstring: @ "<" withstring: @ ""] Stringbyreplacingoccurrencesofstring: @ ">" withstring: @ "" Stringbyreplacingoccurrencesofstring: @ "" WithString: @""];

nsuserdefaults* defs = [Nsuserdefaults standarduserdefaults];

[Defs setvalue:strdev forkey:@ "Devicetoken"];

NSLog (@ "%@", Strdev);

[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Appuploaddevicetoken" object:nil];

}

-(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) error {

NSLog (@ "Error in registration. Error:%@ ", error);

}

-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo

{

NSLog (@ "received push message:%@", [[UserInfo objectforkey:@ "APS"] objectforkey:@ "alert"]);

if ([[UserInfo objectforkey:@ "APS"] objectforkey:@ "alert"]!=null) {

uialertview* alert = [[Uialertview alloc] initwithtitle:@ "Push notification"

Message:[[userinfo objectforkey:@ "APS"] objectforkey:@ "alert"]

Delegate:self

cancelbuttontitle:@ "Off"

otherbuttontitles:@ "Update Status", nil];

[Alert show];

//    }

}

-(void) Applicationwillresignactive: (uiapplication *) application

{

Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state.

Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

-(void) Applicationdidenterbackground: (uiapplication *) application

{

Use the This method to release the shared resources, save user data, invalidate timers, and store enough application state info Rmation to the restore your application to the it is terminated later.

If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits.

[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Appdisconnectchatserver" object:nil];

Nsuserdefaults *pref = [Nsuserdefaults standarduserdefaults];

[Pref setvalue:@ "" forkey:@ "pwd"];

Server-side launch login;

NSString *strtoken = [pref stringforkey:@ "Logintoken"];

NSString *strurl = [NSString stringwithformat:@ "%@/applogout?token=%@", Web_server_host,strtoken];

Nsurl *url = [Nsurl Urlwithstring:strurl];

__block asihttprequest *request = [ASIHTTPRequest Requestwithurl:url];

[Request setcompletionblock:^{

NSString *responsestring = [request responsestring];

NSLog (@ "Exit login%@", responsestring);

Nserror *error = nil;

NSData *jsondata = [responsestring datausingencoding:nsutf8stringencoding];

Nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:&error];

NSString *msgcode = [dict objectforkey:@ "Code"];

if ([Msgcode isequaltostring:@ "200"]) {

NSLog (@ "Successful exit!");

Uialertview *alert =[[Uialertview alloc] Initwithtitle:nil message:@ "Successful exit" Delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil];

[Alert show];

}

}];

[Request setfailedblock:^{

Nserror *error = [request ERROR];

NSLog (@ "Log out failed" error is%@ ", error.description);

}];

[Request startasynchronous];

}

-(void) Applicationwillenterforeground: (uiapplication *) application

{

Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the background.

Nsuserdefaults *pref = [Nsuserdefaults standarduserdefaults];

nsstring* struid = [pref stringforkey:@ "UID"];

nsstring* strpwd = [pref stringforkey:@ "pwd"];

//

nsstring* strlogin = [NSString stringwithformat:@ "{\" type\ ": \" login\ ", \" uid\ ": \"%@\ ", \" pwd\ ": \"%@\ "}", Struid, STRPWD];

//

//

//

[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Applogin" object:strlogin];

}

-(void) Applicationdidbecomeactive: (uiapplication *) application

{

Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.

Nsuserdefaults *pref = [Nsuserdefaults standarduserdefaults];

nsstring* struid = [pref stringforkey:@ "UID"];

nsstring* strpwd = [pref stringforkey:@ "pwd"];

nsstring* strlogin = [NSString stringwithformat:@ "{\" type\ ": \" login\ ", \" uid\ ": \"%@\ ", \" pwd\ ": \"%@\ "}", Struid, STRPWD];

[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Applogin" object:strlogin];

[UIApplication sharedapplication].applicationiconbadgenumber = 0;

}

-(void) Applicationwillterminate: (uiapplication *) application

{

Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.

}

@end

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.