@ 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