Encapsulation of huanxin-elementary

Source: Internet
Author: User

@ Interface easemobprocessor: nsobject

+ (Void) Init :( uiapplication *) Application

Launchoptions :( nsdictionary *) launchoptions;

+ (Void) login;

+ (Void) logout;

+ (Void) registedevicetoken :( uiapplication *) Application devicetoken :( nsdata *) devicetoken;

+ (Void) applicationwillresignactive :( uiapplication *) application;

+ (Void) applicationdidenterbackground :( uiapplication *) application;

+ (Void) applicationwillenterforeground :( uiapplication *) application;

+ (Void) applicationdidbecomeactive :( uiapplication *) application;

+ (Void) applicationwillterminate :( uiapplication *) application;

@ End

 

Easemobprocessor. m

# Import "easemobprocessor. H"

# Import "easemob. H"

# Import "appstatus. H"

# Import "userstore. H"

@ Implementation easemobprocessor

+ (Void) Init :( uiapplication *) Application launchoptions :( nsdictionary *) launchoptions {

// Register the name of the apns file, which must match the name of the certificate uploaded in the background.

Nsstring * apnscertname = [appstatus sharedinstance]. easemobapnscertname;

Nslog (@ ">>>>>> export mob config: % @, % @", apnscertname, [appstatus sharedinstance]. easemobappkey );

[[Easemob sharedinstance] registersdkwithappkey: [appstatus sharedinstance]. easemobappkey apnscertname: apnscertname];

[[Easemob sharedinstance] enablebackgroundreceivemessage];

[[Easemob sharedinstance] Application: Application didfinishlaunchingwitexceptions: launchoptions];

}

// Called upon Logon

+ (Void) login {

Appstatus * As = [appstatus sharedinstance];

If (! [As logined] | as. easemoblogined ){

Return;

}

// Pay attention to the judgment here! [As. User. easemobuseruuid isequal: [nsnull null]

If (as. User. easemobuseruuid! = Nil &&! [As. User. easemobuseruuid isequal: [nsnull null]

&&! [As. User. easemobuseruuid isw.tostring: @ ""]) {

Nslog (@ ">>>> easemob Username: % @, PWD: % @", as. User. usercode, as. User. accesstoken );

[[Easemob sharedinstance]. chatmanager asyncloginwithusername: As. User. usercode

Password: As. User. accesstoken

Completion:

^ (Nsdictionary * logininfo, emerror * error ){

If (error ){

Nslog (@ "Logon email failed: % @", error );

} Else {

Nslog (@ "successfully logging on to the email ");

As. easemoblogined = yes;

[Appstatus saveappstatus];

}

} Onqueue: Nil];

} Else {

[Nsthread sleepfortimeinterval: 2];

[Userstore getmyuserinfo: ^ (User * user, nserror * ERR ){

As. User. easemobuseruuid = user. easemobuseruuid;

[Easemobprocessor Login];

}];

}

}

// Exit is a call

+ (Void) logout {

Appstatus * As = [appstatus sharedinstance];

[[Easemob sharedinstance]. chatmanager asynclogoff];

As. easemoblogined = no;

[Appstatus saveappstatus];

 

}

 

+ (Void) registedevicetoken :( uiapplication *) Application devicetoken :( nsdata *) devicetoken {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] Application: Application didregisterforremotenotificationswithdevicetoken: devicetoken];

}

 

+ (Void) applicationwillresignactive :( uiapplication *) Application {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] applicationwillresignactive: Application];

}

 

+ (Void) applicationdidenterbackground :( uiapplication *) Application {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] applicationdidenterbackground: Application];

}

 

+ (Void) applicationwillenterforeground :( uiapplication *) Application {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] applicationwillenterforeground: Application];

}

 

+ (Void) applicationdidbecomeactive :( uiapplication *) Application {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] applicationdidbecomeactive: Application];

[Easemobprocessor Login];

}

 

+ (Void) applicationwillterminate :( uiapplication *) Application {

// Obtain the current status of the app for the SDK to perform operations in the current scenario.

[[Easemob sharedinstance] applicationwillterminate: Application];

}

 

@ 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.