JPush

1.https://www.jpush.cn/极光网创建新的应用

JPush_第1张图片

2.https://developer.apple.com苹果开发者网站<1>钥匙串创建证书请求、<2>申请开发者证书、<3>创建APPID、<4>申请provision文件。。。。。<5>钥匙串创建证书请求、<6>创建APNS推送通知证书。

3.APNS推送通知证书导出p12文件,上传到极光网(开发环境:已验证)表示证书上传成功。

4.创建配置PushConfig.plist文件,修改info.plist的Bundle identifier与苹果开发者网站上APPID一致。

JPush_第2张图片

JPush_第3张图片

4代码集成

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

self.window.backgroundColor= [UIColorwhiteColor];

[self.windowmakeKeyAndVisible];

//————————————————点击远程推送通知消息进入APP——————————————//

NSLog(@"_________launchOptions_________ = %@",launchOptions);

if(launchOptions) {

NSDictionary*userInfo = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

_userInfo= userInfo;

//        [self presentViewControllerWithUserInfo:userInfo];

//        NSLog(@">>>launchOptions.message<<<< = %@",[launchOptions objectForKey:@"message"]);

}

////————————————————————极光推送Required————————————————————

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

if([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0) {

//可以添加自定义categories

[APServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge|

UIUserNotificationTypeSound|

UIUserNotificationTypeAlert)

categories:nil];

}else{

//categories必须为nil

[APServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|

UIRemoteNotificationTypeSound|

UIRemoteNotificationTypeAlert)

categories:nil];

}

#else

//categories必须为nil

[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)

categories:nil];

#endif

// Required

[APServicesetupWithOption:launchOptions];

self.window.rootViewController= [[TabBarViewControlleralloc]init];

returnYES;

}

#pragma mark -消息跳转页面

- (void)presentViewControllerWithUserInfo:(NSDictionary*)userInfo {

//拿出消息内容,跳转即可~~~~

_userInfo= userInfo;

UIAlertView*remoteNotification = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"您的安装视频通过审核,请点击确定进入一键激活"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

[remoteNotificationshow];

}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex ==0) {

UIStoryboard*fafangStoryboard = [UIStoryboardstoryboardWithName:@"FaFang"bundle:nil];

LFNavigationViewController*lfVC = [fafangStoryboardinstantiateViewControllerWithIdentifier:@"LFNavigationViewController"];

NSLog(@"&&&&&%@&&&&&&",lfVC);

BluetoothViewController*blueVC = [fafangStoryboardinstantiateViewControllerWithIdentifier:@"BluetoothViewController"];

blueVC.userInfo=_userInfo;

[self.window.rootViewControllerpresentViewController:lfVCanimated:YEScompletion:nil];

[lfVCpushViewController:blueVCanimated:YES];

}

}

- (void)applicationWillResignActive:(UIApplication*)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication*)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

[applicationsetApplicationIconBadgeNumber:0];

}

- (void)applicationWillEnterForeground:(UIApplication*)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

[applicationsetApplicationIconBadgeNumber:0];

[applicationcancelAllLocalNotifications];

}

- (void)applicationDidBecomeActive:(UIApplication*)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication*)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

#pragma mark -极光推送

/*************极光推送****************/

- (void)application:(UIApplication*)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

{

NSLog(@"%@", [NSStringstringWithFormat:@"Device Token: %@", deviceToken]);

[APServiceregisterDeviceToken:deviceToken];

NSLog(@"APService registrationID:%@",[APServiceregistrationID]);

/*

设置设置别名(alias)与标签(tags)

别名alias每个用户只能指定一个别名

标签tag可为每个用户打多个标签

*/

[APServicesetTags:[NSSetsetWithObjects:@"tag1",nil]alias:@"testOBU-0000000"callbackSelector:@selector(tagsAliasCallback:tags:alias:)target:self];

}

//设置别名(alias)与标签(tags)回掉函数。

- (void)tagsAliasCallback:(int)iResCode

tags:(NSSet*)tags

alias:(NSString*)alias {

NSLog(@"iResCode = %d,tags = %@服务器返回的结果:%@",iResCode,tags,alias);

}

- (void)application:(UIApplication*)application

didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {

NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);

}

//- (void)tagsAliasCallback:(int)iResCode tags:(NSSet*)tags alias:(NSString*)alias {

//    NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias);

//}

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

- (void)application:(UIApplication*)application

didRegisterUserNotificationSettings:

(UIUserNotificationSettings*)notificationSettings {

}

// Called when your app has been activated by the user selecting an action from

// a local notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication*)application

handleActionWithIdentifier:(NSString*)identifier

forLocalNotification:(UILocalNotification*)notification

completionHandler:(void(^)())completionHandler {

}

// Called when your app has been activated by the user selecting an action from

// a remote notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication*)application

handleActionWithIdentifier:(NSString*)identifier

forRemoteNotification:(NSDictionary*)userInfo

completionHandler:(void(^)())completionHandler {

}

#endif

//————————————APP正在前台或者后台运行,此函数会被调用————————————//

- (void)application:(UIApplication*)application

didReceiveRemoteNotification:(NSDictionary*)userInfo {

[APServicehandleRemoteNotification:userInfo];

NSLog(@":+++++++收到通知+++++++:%@", [selflogDic:userInfo]);

// [rootViewController addNotificationCount];

/*

if (application.applicationState != UIApplicationStateActive) {

[self presentViewControllerWithUserInfo:userInfo];

}

*/

}

//————————————APP正在前台或者后台运行,此函数会被调用————————————//

- (void)application:(UIApplication*)application

didReceiveRemoteNotification:(NSDictionary*)userInfo

fetchCompletionHandler:

(void(^)(UIBackgroundFetchResult))completionHandler {

[APServicehandleRemoteNotification:userInfo];

NSLog(@">>>>>>收到通知<<<<<<:%@", [selflogDic:userInfo]);

//   [rootViewController addNotificationCount];

completionHandler(UIBackgroundFetchResultNewData);

if(application.applicationState!=UIApplicationStateActive) {

[selfpresentViewControllerWithUserInfo:userInfo];

}

}

// log NSSet with UTF8

// if not ,log will be \Uxxx

- (NSString*)logDic:(NSDictionary*)dic {

if(![diccount]) {

returnnil;

}

NSString*tempStr1 =

[[dicdescription]stringByReplacingOccurrencesOfString:@"\\u"

withString:@"\\U"];

NSString*tempStr2 =

[tempStr1stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];

NSString*tempStr3 =

[[@"\""stringByAppendingString:tempStr2]stringByAppendingString:@"\""];

NSData*tempData = [tempStr3dataUsingEncoding:NSUTF8StringEncoding];

NSString*str =

[NSPropertyListSerializationpropertyListFromData:tempData

mutabilityOption:NSPropertyListImmutable

format:NULL

errorDescription:NULL];

returnstr;

}

- (void)viewWillAppear:(BOOL)animated {

[APServicestartLogPageView:@"PageOne"];

}

- (void)viewWillDisappear:(BOOL)animated {

[APServicestopLogPageView:@"PageOne"];

}

//-(void)trackView {

//

//    [APService beginLogPageView:@"PageTwo" duration:10];

//}

你可能感兴趣的:(JPush)