|
@@ -20,7 +20,7 @@
|
|
|
#import "JYTabBarController.h"
|
|
|
|
|
|
|
|
|
-@interface AppDelegate ()<JPUSHRegisterDelegate,WXApiDelegate>
|
|
|
+@interface AppDelegate ()<JPUSHRegisterDelegate,WXApiDelegate,UNUserNotificationCenterDelegate>
|
|
|
|
|
|
@property(nonatomic, strong)UIImageView *imgView;
|
|
|
@property(nonatomic, assign)BOOL wakeUpBool;
|
|
@@ -42,8 +42,11 @@
|
|
|
[LXDataBaseManager shareDataBaseManager];//初始化单例
|
|
|
[LXViewControllerManager shareViewControllerManager];
|
|
|
|
|
|
- [self initJPush:launchOptions];
|
|
|
+// [self initJPush:launchOptions];
|
|
|
[self initUM];
|
|
|
+ [self registeredPush]; //注册原生推送
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -62,27 +65,15 @@
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
-(void)initJPush:(NSDictionary *)launchOptions{
|
|
|
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
|
|
|
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
|
|
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
|
|
- // 可以添加自定义categories
|
|
|
- // NSSet<UNNotificationCategory *> *categories for iOS10 or later
|
|
|
- // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
|
|
|
- // UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
|
|
|
- // [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
|
|
|
+
|
|
|
}
|
|
|
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
|
|
|
-
|
|
|
- // Optional
|
|
|
- // 获取IDFA
|
|
|
- // 如需使用IDFA功能请添加此代码并在初始化方法的advertisingIdentifier参数中填写对应值
|
|
|
- // NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
|
|
-
|
|
|
- // Required
|
|
|
- // init Push
|
|
|
- // notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil
|
|
|
- // 如需继续使用pushConfig.pinfo文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
|
|
|
+
|
|
|
[JPUSHService setupWithOption:launchOptions appKey:@"5efa1257867cf5d77d007ce6"
|
|
|
channel:@"APP Store"
|
|
|
apsForProduction:1
|
|
@@ -126,6 +117,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
+#pragma mark 原生推送
|
|
|
+-(void)registeredPush
|
|
|
+{
|
|
|
+ if (@available(iOS 10.0, *)) {
|
|
|
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
+ center.delegate = self;
|
|
|
+ // 小角标、声音、弹窗
|
|
|
+ if (@available(iOS 10.0, *)) {
|
|
|
+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
|
|
+ if (!error) {
|
|
|
+ NSLog(@"request authorization succeeded!");
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ // Fallback on earlier versions
|
|
|
+ }
|
|
|
+
|
|
|
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
|
+
|
|
|
+ } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
|
|
|
+ UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
|
|
|
+ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
|
|
|
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
|
+ [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
|
|
|
+ }else {
|
|
|
+ UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeBadge);
|
|
|
+ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// iOS 10: App在前台获取到通知
|
|
|
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
|
|
+
|
|
|
+ NSLog(@"willPresentNotification:%@", notification.request.content.userInfo);
|
|
|
+
|
|
|
+ // 处理 推送数据
|
|
|
+ NSDictionary *contentDic=notification.request.content.userInfo;
|
|
|
+// [self handleDic:contentDic];
|
|
|
+
|
|
|
+ // 根据APP需要,判断是否要提示用户Badge、Sound、Alert
|
|
|
+ if (@available(iOS 10.0, *)) {
|
|
|
+ completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
|
|
|
+ } else {
|
|
|
+ // Fallback on earlier versions
|
|
|
+ }
|
|
|
+}
|
|
|
+// iOS 10: 点击通知进入App时触发
|
|
|
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
|
|
|
+ NSLog(@"didReceiveNotification:%@", response.notification.request.content.userInfo);
|
|
|
+ // 处理 推送数据
|
|
|
+ NSDictionary *contentDic=response.notification.request.content.userInfo;
|
|
|
+// [self handleDic:contentDic];
|
|
|
+ completionHandler();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -171,12 +224,20 @@
|
|
|
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
|
|
|
/// Required - 注册 DeviceToken
|
|
|
- [JPUSHService registerDeviceToken:deviceToken];
|
|
|
+// [JPUSHService registerDeviceToken:deviceToken];
|
|
|
+
|
|
|
+ // 收到token
|
|
|
+ NSString *token =
|
|
|
+ [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|
|
+ // 保存到后台-用于推送
|
|
|
+ NSLog(@"%@",token)
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
|
|
|
//Optional
|
|
|
- NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
|
|
|
+ NSLog(@"注册APNS失败:%@",error);
|
|
|
}
|
|
|
|
|
|
// iOS 10 Support
|
|
@@ -268,7 +329,7 @@ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+// 收到推送时调用(iOS7-iOS9)
|
|
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
|
|
NSLog(@"111");
|
|
|
NSLog(@"%@",userInfo);
|
|
@@ -332,7 +393,7 @@ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
completionHandler(UIBackgroundFetchResultNewData);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+// 收到推送时调用(iOS6及以下)
|
|
|
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
|
|
// App 收到推送的通知
|
|
|
NSLog(@"********** ios7.0之前 **********");
|