JPush

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

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一致。

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];

//}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 苹果在iOS10上对apns推送做了修改, 极光也是很给力的, 在第一时间就对sdk进行了更新, 下面对iOS10...
    XLsn0w阅读 7,150评论 1 0
  • 前言 推送服务可以说是所有 App 的标配,不论是哪种类型的 App,推送都从很大程度上决定了 App 的 打开率...
    進无尽阅读 11,005评论 0 2
  • 安装 安装,打开终端项目目录下运行,安卓jpush-react-native jpush-react-nativ...
    45b645c5912e阅读 8,863评论 0 4
  • ReactNative 整合极光推送jpush-react-native(Android端) http://www...
    Loki_阅读 6,846评论 3 1
  • 村里的夜晚黑漆漆,静悄悄,在街上晃悠,突然意识到以后见姥姥的机会将会越来越少,于是掉头。“姥姥,找什么呢?”听到我...
    帅气的昵称100阅读 1,735评论 0 0