Aurora Push Package

Source: Internet
Author: User
Tags vars

  1. //

    JGPushHelp.h

    wyb

    //

    Created by Amoy Yuan Lok on 15/7/29.

    Copyright (c) 2015 China Model. All rights reserved.

    //

    #import <Foundation/Foundation.h>

    #import <UIKit/UIKit.h>

    @interface Jgpushhelp:nsobject

    Called when the app is started

    + (void) Setupwithoptions: (Nsdictionary *) launchoptions;

    Called at the Appdelegate registration device

    + (void) Registerdevicetoken: (NSData *) Devicetoken;

    After iOS7, only completion, otherwise pass nil

    + (void) Handleremotenotification: (nsdictionary *) UserInfo Completion: (void (^) (uibackgroundfetchresult)) completion ;

    Show local notifications at the front

    + (void) Showlocalnotificationatfront: (uilocalnotification *) notification;

    @end

    //

    jgpushhelp.m

    wyb

    //

    Created by Amoy Yuan Lok on 15/7/29.

    Copyright (c) 2015 China Model. All rights reserved.

    //

    #import "JGPushHelp.h"

    #import "APService.h"

    @implementation Jgpushhelp

    + (void) Setupwithoptions: (Nsdictionary *) launchoptions {

    Required

    #if __iphone_os_version_max_allowed > __iphone_7_1

    You can customize the category after iOS8

    if ([[Uidevice currentdevice].systemversion Floatvalue] >= 8.0) {

    You can add a custom categories

    [Apservice registerforremotenotificationtypes: (Uiusernotificationtypebadge |

    Uiusernotificationtypesound |

    Uiusernotificationtypealert)

    Categories:nil];

    } else {

    #if __iphone_os_version_max_allowed < __iphone_8_0

    iOS8 before the categories must be nil

    [Apservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |

    Uiremotenotificationtypesound |

    Uiremotenotificationtypealert)

    Categories:nil];

    #endif

    }

    #else

    The categories must be nil.

    [Apservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |

    Uiremotenotificationtypesound |

    Uiremotenotificationtypealert)

    Categories:nil];

    #endif

    Required

    [Apservice setupwithoption:launchoptions];

    Return

    }

    + (void) Registerdevicetoken: (NSData *) Devicetoken {

    [Apservice Registerdevicetoken:devicetoken];

    Return

    }

    + (void) Handleremotenotification: (nsdictionary *) UserInfo Completion: (void (^) (uibackgroundfetchresult)) completion {

    [Apservice Handleremotenotification:userinfo];

    if (completion) {

    Completion (Uibackgroundfetchresultnewdata);

    }

    Return

    }

    + (void) Showlocalnotificationatfront: (uilocalnotification *) Notification {

    [Apservice showlocalnotificationatfront:notification Identifierkey:nil];

    Return

    }

    @end

  2. //
  3. Appdelegate.m
  4. wyb
  5. //
  6. // Created by Amoy Yuan Lok on 15/7/29.
  7. Copyright (c) 2015 China Model. All rights reserved.  
  8. //
  9. #import "AppDelegate.h"
  10. #import "JGPushHelp.h"

  11. @interface Appdelegate ()
  12. @end
  13. @implementation Appdelegate
  14. -(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions {
  15. self. window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];
  16. //Override point for customization after application launch.
  17. [Jgpushhelp setupwithoptions:launchoptions];
  18. self. Window. backgroundcolor = [Uicolor whitecolor];
  19. [Self. window makekeyandvisible];
  20. return YES;
  21. }
  22. -(void) application: (uiapplication *) application Didregisterforremotenotificationswithdevicetoken: ( NSData *) devicetoken {
  23. [Jgpushhelp Registerdevicetoken:devicetoken];
  24. return;
  25. }
  26. -(void) application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo {
  27. [Jgpushhelp handleremotenotification:userinfo completion: nil];
  28. return;
  29. }
  30. #if __iphone_os_version_max_allowed >= __iphone_7_0
  31. This function is only possible after ios7.0
  32. -(void) application: (uiapplication *) application didreceiveremotenotification
  33. :(nsdictionary *) userInfo Fetchcompletionhandler
  34. :(void (^) (uibackgroundfetchresult)) Completionhandler {
  35. [Jgpushhelp handleremotenotification:userinfo Completion:completionhandler];
  36. //application is processing foreground state, will not receive push message, so here need to deal with the extra
  37. if (application. applicationstate = = uiapplicationstateactive) {
  38. Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Receive push message"
  39. message:userinfo[@ "APS" [@ "alert"]
  40. delegate: nil
  41. cancelbuttontitle:@ "Cancel"
  42. otherbuttontitles:@ "OK", nil nil];
  43. [Alert Show];
  44. }
  45. return;
  46. }
  47. #endif
  48. -(void) application: (uiapplication *) application didreceivelocalnotification: (uilocalnotification *) Notification {
  49. [Jgpushhelp showlocalnotificationatfront:notification];
  50. return;
  51. }
  52. -(void) application: (uiapplication *) app Didfailtoregisterforremotenotificationswitherror: ( Nserror *) Err {
  53. NSLog (@ "Error in registration.  Error:%@ ", err);
  54. }
  55. -(void) applicationdidbecomeactive: (uiapplication *) application {
  56. [Application Setapplicationiconbadgenumber:0];
  57. return;
  58. }
  59. @end

Aurora Push Package

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.