Third party-laser push 2.1.0

Source: Internet
Author: User

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

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.