1. First create a category
#import "appdelegate+jpush.h"#import "JPUSHService.h"#import "WJNotifier.h"//Dependent FilesStaticNSString *jiguang_push_key =@"4cdcd543c073753fb8932246";//Key//nsstring *_tag = nil;@implementationappdelegate (Jpush)- (void) Initjpush: (Nsdictionary *) launchoptions{if([[Uidevice currentdevice].systemversion Floatvalue] >=8.0) { //You can add a custom categories[Jpushservice registerforremotenotificationtypes: (Uiusernotificationtypebadge |Uiusernotificationtypesound|Uiusernotificationtypealert) Categories:nil]; } Else { //the categories must be nil .[Jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |Uiremotenotificationtypesound|Uiremotenotificationtypealert) Categories:nil]; } //Required//If you need to be compatible with older versions, use the [Jpushservice Setupwithoption:launchoptions] method to initialize and simultaneously use the Pushconfig.plist file to declare the configuration content such as Appkey. [Jpushservice setupwithoption:launchoptions Appkey:jiguang_push_key Channel:@"0"Apsforproduction:yes];}- (void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {//Required[Jpushservice Registerdevicetoken:devicetoken];}- (void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {//Required,for systems with less than or equal to IOS6[Jpushservice handleremotenotification:userinfo];}- (void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void(^) (Uibackgroundfetchresult)) Completionhandler {//IOS 7 Support Required[Jpushservice Handleremotenotification:userinfo]; Completionhandler (Uibackgroundfetchresultnewdata); if(Application.applicationstate = =uiapplicationstateactive) { //The sound is playing inside[Wjnotifier shownotifer:userinfo[@"APS"][@"Alert"]]; } [Coremanager Setjpushnumber]; [[Nsnotificationcenter Defaultcenter]postnotificationname:notice_jpushObject:@"1"];}- (void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error {//OptionalNSLog (@"Did Fail to Register for Remote notifications with Error:%@", error);}@end
2. Call initialize in the following method
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
3. Listening status in the root controller
- (void) Dealloc {[Self unobserveallnotifications];}- (void) viewdidload {[Super viewdidload];Nsnotificationcenter*defaultcenter =[Nsnotificationcenter Defaultcenter]; [Defaultcenter addobserver:self selector: @selector (networkdidsetup:) name:kj PfnetworkdidsetupnotificationObject: nil]; [Defaultcenter addobserver:self selector: @selector (networkdidclose:) name:kj PfnetworkdidclosenotificationObject: nil]; [Defaultcenter addobserver:self selector: @selector (networkdidregister:) name : KjpfnetworkdidregisternotificationObject: nil]; [Defaultcenter addobserver:self selector: @selector (networkdidlogin:) name:kj PfnetworkdidloginnotificationObject: nil]; [Defaultcenter addobserver:self selector: @selector (networkdidreceivemessage:) Name:kjpfnetworkdidreceivemessagenotificationObject: nil]; [Defaultcenter addobserver:self selector: @selector (serviceerror:) NAME:KJPFS ErviceerrornotificationObject: nil]; }- (void) unobserveallnotifications {nsnotificationcenter*defaultcenter =[Nsnotificationcenter Defaultcenter]; [Defaultcenter removeobserver:self Name:kjpfnetworkdidsetupnotification Object: nil]; [Defaultcenter removeobserver:self Name:kjpfnetworkdidclosenotification Object: nil]; [Defaultcenter removeobserver:self Name:kjpfnetworkdidregisternotification Object: nil]; [Defaultcenter removeobserver:self Name:kjpfnetworkdidloginnotification Object: nil]; [Defaultcenter removeobserver:self Name:kjpfnetworkdidreceivemessagenotification Object: nil]; [Defaultcenter removeobserver:self Name:kjpfserviceerrornotification Object: nil];}- (void) Networkdidsetup: (Nsnotification *) Notification {NSLog (@"is connected");}- (void) Networkdidclose: (Nsnotification *) Notification {}- (void) Networkdidregister: (Nsnotification *) Notification {NSLog (@"%@", [notification userInfo]); NSLog (@"already registered");}- (void) Networkdidlogin: (Nsnotification *) Notification {NSLog (@"is logged in"); if([Jpushservice Registrationid]) {NSLog (@"Get Registrationid");
Transfer to alias [self Resetaliasandtagwithtag:[usermanager shareduserinfowithplist].name]; }}- (void) Networkdidreceivemessage: (Nsnotification *) Notification {}- (void) Serviceerror: (Nsnotification *) Notification {nsdictionary*userinfo =[Notification UserInfo]; NSString*error = [UserInfo valueforkey:@"Error"]; NSLog (@"%@", error);}- (void) Resetaliasandtagwithtag: (NSString *) tag{__autoreleasing nsmutableset* tags = [nsmutablesetSet]; if(Tag = =Nil) {[Tags AddObject:@""]; }Else{[tags addobject:tag]; } //no direct pass in @ ""[Jpushservice Settags:[nssetSet] Alias:tag callbackselector: @selector (tagsAliasCallback:tags:alias:)Object: self];}- (void) Tagsaliascallback: (int) Irescode Tags: (nsset*) Tags alias: (nsstring*) alias{NSLog (@"%d", Irescode); NSLog (@"the label is set successfully and the label is named%@", alias); Switch(irescode) { Case 6002: [Self resetaliasandtagwithtag:[usermanager shareduserinfowithplist].name]; Break; default:; } }
Third party-laser push 2.1.0