IOS remote Push umeng Push and iospush
One task after I joined the company is remote Push. I heard the boss say that umeng push is used. So I checked umeng Push. For details about integration and certificate generation, refer to here. I will not talk about it more specifically, but I re-encapsulate the UMessage. The specific content is as follows:
//// ZGUmessagePush. h // NotePad /// Created by zhanggui on 15/10/19. // Copyright©2015 xiaoguizi. all rights reserved. // # import <Foundation/Foundation. h> # import <CoreLocation/CoreLocation. h> # import "UMessage. h "typedef void (^ ResponsData) (id responseObject, NSError * error); @ interface ZGUmessagePush: NSObject @ property (nonatomic, strong) NSDictionary * receiveDic; + (instancetype) shared; /*** add umeng push */+ (void) startaddumessagewitexceptions :( NSDictionary *) launchOptions;/*** register the device */+ (void) registerDeviceWithToken :( NSData *) data; /*** receive message **/+ (void) didReceiveRemoteNotification :( NSDictionary *) receiveInfoMation;/***** disable notification for receiving messages */+ (void) closeUmessageNotification; /*** use the default prompt provided by umeng to display */+ (void) setCustomShow :( BOOL) isShow;/*** to customize the Display message processing, receiveDic is the pushed content * @ param receiveDic refers to the pushed information */+ (void) handleReceiveData :( NSDictionary *) receiveDic; /*** whether to allow the SDK to automatically clear the badge (enabled by default) * @ param boo yes clear, no automatically clear */+ (void) setApplicationBadegeClear :( BOOL) boo; /*** set whether to allow the SDK to pop up the Alert box (enabled by default) when the app receives the Push when running on the foreground * @ param boo yes indicates that the alert box is displayed when the foreground is allowed to run, no: */+ (void) setShowAutoAlert :( BOOL) boo;/*** set geographic location information * @ param location: Geographic Information */+ (void) setLocation :( CLLocation *) location;/*** Add Tag * @ param tagArray, used to hold the tag to be added */+ (void) addTags :( NSArray *) tagArray; /** bind an individual name to the device (including the account and platform type) @ warning. A prerequisite for adding Alias is that device_token has been obtained successfully; otherwise, the device fails (kUMessageErrorDependsErr) @ param alias account, for example, for the email @ param type platform type, see 'kumessagealiastype... ', for example: kUMessageAliasTypeSina @ param data, error indicates the information returned when the query fails, and responseObject indicates the data returned successfully */+ (void) addAlias :( NSString *) alias type :( NSString *) type response :( ResponsData) data;/** a prerequisite for deleting a device Alias binding @ warning to delete alias is that device_token has been obtained successfully, otherwise, the failure (kUMessageErrorDependsErr) @ param alias account, such as the email @ param type platform type. For details, see 'kumessagealiastype... ', for example, the kUMessageAliasTypeSina @ param response block returns data, the error is the information returned when the query fails, and the responseObject is the data returned successfully */+ (void) deleteAlias :( NSString *) alias type :( NSString *) type response :( ResponsData) data; @ end
The above is a. h file.
//// ZGUmessagePush. m // NotePad /// Created by zhanggui on 15/10/19. // Copyright©2015 xiaoguizi. all rights reserved. // # import "ZGUmessagePush. h "# import <UIKit/UIKit. h> # import "LoginViewController. h "# import" LeftTableViewController. h "# define _ IPHONE80 _ 80000 # define APPKEY @" 5620da47e0f55a062b003b57 "# define Merge (v) ([[[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch]! = NSOrderedAscending) @ implementation ZGUmessagePush + (instancetype) shared {static ZGUmessagePush * sharedPush = nil; static extends onceToken; dispatch_once (& onceToken, ^ {sharedPush = [[ZGUmessagePush alloc] init] ;}); return sharedPush ;}+ (void) implements :( NSDictionary *) launchOptions {[UMessage startWithAppkey: APPKEY launchOptions: launchOptions]; # if _ IPHONE_ OS _VERSION_M AX_ALLOWED> = _ IPHONE80 _ if (UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (@ "8.0") {// register remoteNotification types (iOS 8.0 and later versions) UIMutableUserNotificationAction * action1 = [[UIMutableUserNotificationAction alloc] init]; action1.identifier = @ "action1_identifier"; action1.title = @ "Accept"; action1.activationMode = enabled; // start the handler program when you click Ction * action2 = [[UIMutableUserNotificationAction alloc] init]; // the second button action2.identifier = @ "action2_identifier"; action2.title = @ "Reject"; action2.activationMode = UIUserNotificationActivationModeBackground; // if you do not start the program when you click it, process action2.authenticationRequired = YES in the background; // you need to unlock it to process it. activationMode = UIUserNotificationActivationModeForeground; this attribute is ignored; action2.destructive = YES; UIMutableUserNoti FicationCategory * categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys. identifier = @ "category1"; // the unique identifier of this group of actions [categorys setActions: @ [action1, action2] forContext :( category)]; UIUserNotificationSettings * userSettings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categ Ories: [NSSet setWithObject: categorys]; [UMessage failed: userSettings];} else {// register remotenoication types (iOS 8.0 or lower) [UMessage registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | uiremotenotiftypetypesound | UIRemoteNotificationTypeAlert];} # else // register remoteNotification types (less than iOS 8.0) [UMessage registerForRemoteNoti FicationTypes: Custom | UIRemoteNotificationTypeSound | audio]; # endif # if DEBUG [UMessage setLogEnabled: YES]; # endif [UMessage setLogEnabled: NO] ;}+ (void) Upload :( NSDictionary *) receiveInfoMation {[UMessage didReceiveRemoteNotification: receiveInfoMation];} + (void) registerDeviceWithToken :( NSData *) data {NSString * deveiceToken = [NSSt Ring stringWithFormat: @ "% @", data]; deveiceToken = [deveiceToken token: @ "" withString: @ ""]; NSLog (@ "deveice-token: % @", deveiceToken); [UMessage registerDeviceToken: data];} + (void) handle {[UMessage handle];} + (void) setCustomShow :( BOOL) isShow {[UMessage setAutoAlert: isShow];} // returned push information: aps and d. p is brought by UMessage, and gender is added by itself //{// Aps = {// alert = "\ U8868 \ U793a \ U5185 \ U5bb9 \ U90a3 \ U4e2a"; // badge = 1; // sound = default ;//}; // d = us88294144523914949311; // gender = girl; // p = 0; //} + (void) handleReceiveData :( NSDictionary *) receiveDic {[UMessage setAutoAlert: NO]; // if ([UIApplication sharedApplication]. applicationIconBadgeNumber! = 0) {[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; // set the badge to 0, that is, not displayed} // if ([UIApplication sharedApplication]. applicationState! = UIApplicationStateActive) {NSLog (@ "UMessage: Start processing program logic processing"); UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "title" message: [receiveDic objectForKey: @ "name"] delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show];} else {NSLog (@ "UMessage: The program is running on the foreground, by default, no processing is performed "); }}+ (void) addTags :( NSArray *) tagArray {if ([tagArray isKindOfClass: [NSArray class]) {if ([tagArray count] = 0) {NSLog (@ "No tag added"); return;} else {[UMessage addTag: tagArray response: ^ (id responseObject, NSInteger remain, NSError * error) {if (error) {NSLog (@ "tag addition failed") ;}}}+ (void) addAlias :( NSString *) alias type :( NSString *) type response :( ResponsData) data {[UMessage addAlias: alias type: type response: data] ;}+ (void) deleteAlias :( NSString *) alias type :( NSString *) type response :( ResponsData) data {[UMessage removeAlias: alias type: type response: data] ;}+ (void) setApplicationBadegeClear :( BOOL) boo {[UMessage setBadgeClear: boo] ;}+ (void) setShowAutoAlert :( BOOL) boo {[UMessage setAutoAlert: boo] ;}+ (void) setLocation :( CLLocation *) location {[UMessage setLocation: location];} @ end
Note:
1. If it is a development environment, you need to add the deviceToken to the umeng push backend.
2. Redirect between different pages based on the passed fields is performed in handleReceiveData: This method.
Appendix:
Class: http://pan.baidu.com/s/1o6kZbrc