Third-party-laser push 2.1.0 and third-party laser push 2.1.0

Source: Internet
Author: User

Third-party-laser push 2.1.0 and third-party laser push 2.1.0

1. Create a category first

# Import "AppDelegate + JPush. h "# import" JPUSHService. h "# import" WJNotifier. h "// dependent file static NSString * JIGUANG_PUSH_KEY = @" 4cd543c073753fb8932246 "; // key // NSString * _ tag = nil; @ implementation AppDelegate (JPush)-(void) initJpush :( NSDictionary *) launchOptions {if ([UIDevice currentDevice]. systemVersion floatValue]> = 8.0) {// you can add custom categories [JPUSHService registerForRemoteNotificationTypes :( UIUserNo TificationTypeBadge | uiusernotiftypetypesound | UIUserNotificationTypeAlert) categories: nil];} else {// categories must be nil [JPUSHService category :( optional | category) categories: nil];} // Required // if you need to be compatible with the earlier version, use the [JPUSHService setupWithOption: launchOptions] method to initialize and use pushConfig at the same time. plist file declaration appKe Y. [JPUSHService setupWithOption: launchOptions appKey: JIGUANG_PUSH_KEY channel: @ "0" apsForProduction: YES];}-(void) application :( UIApplication *) application metadata :( 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 metadata :( NSDictionary *) userInfo fetchCompletionHandler :( void (^) (UIBackgroundFetchResult) completionHandler {// IOS 7 Support Required [JPUSHService handleRemoteNotification: userInfo]; completionHandler (UIBackgroundFetchResultNewData); if (application. applicationState = UIApplicationStateActive) {// audio playback in it [WJNotifier showNotifer: userInfo [@ "aps"] [@ "alert"];} [CoreManager setJPushNumber]; [[nsicationcenter center defacenter center] postNotificationName: notice_jpush object: @ "1"];}-(void) application :( UIApplication *) application didFailToRegisterForRemoteNotificationsWithError :( NSError *) error {// Optional NSLog (@ "did Fail To Register For Remote communications With Error: % @", error);} @ end

 

2. Call initialization in the following method

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions

 

3. Monitor the status in the root Controller

-(Void) dealloc {[self timer];}-(void) viewDidLoad {[super viewDidLoad]; nsicationicationcenter * defaultCenter = [nsicationicationcenter defacenter center]; [defacenter center addObserver: self selector: @ selector (networkDidSetup :) name: kJPFNetworkDidSetupNotification object: nil]; [defaultCenter addObserver: self selector: @ selector (networkDidClose :) name: jsonobject: nil]; [defaultCenter addObserver: self selector: @ selector (networkDidRegister :) name: jsonobject: nil]; [defaultCenter addObserver: self selector: @ selector (networkDidLogin :) name: jsonobject: nil]; [defaultCenter addObserver: self selector: @ selector (networkDidReceiveMessage :) name: jsonobject: nil]; [defaultCenter addObserver: self selector: @ selector (serviceError :) name: kJPFServiceErrorNotification object: nil];}-(void) unobserveallnotiications {NSNotificationCenter * defacenter center = [nsnotifcenter center defacenter center]; [defaultCenter removeObserver: self name: jsonobject: nil]; [defacenter center removeObserver: self name: jsonobject: nil]; [defacenter center removeObserver: self name: kJPFNetworkDidRegisterNotification object: nil]; [defacenter center removeObserver: self name: jsonobject: nil]; [defacenter center removeObserver: self name: jsonobject: nil]; [defacenter center removeObserver: self name: kJPFServiceErrorNotification object: nil];}-(void) networkDidSetup :( NSNotification *) notification {NSLog (@ "connected");}-(void) networkDidClose :( NSNotification *) notification {}-(void) networkDidRegister :( NSNotification *) notification {NSLog (@ "% @", [notification userInfo]); NSLog (@ "registered");}-(void) networkDidLogin :( NSNotification *) notification {NSLog (@ "logged on"); if ([JPUSHService registrationID]) {NSLog (@ "get RegistrationID ");
// Transfer alias [self resetAliasAndTagWithTag: [UserManager shareduserinfowit2d-ist]. 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 = [NSMutableSet set]; if (tag = nil) {[tags addObject: @ ""];} else {[tags addObject: tag];} // no direct input @ "" [JPUSHService setTags: [NSSet set] alias: tag callbackSelector: @ selector (tagsAliasCallback: tags: alias :) object: self];} -(void) tagsAliasCallback :( int) iResCode tags :( NSSet *) tags alias :( NSString *) alias {NSLog (@ "% d", iResCode ); NSLog (@ "tag set successfully, tag name % @", alias); switch (iResCode) {case 6002: [self resetAliasAndTagWithTag: [UserManager shareduserinfowit2d-ist]. name]; break; default :;}}

 

Related Article

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.