iOS-集成阿里云移动推送,跳转任意界面

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if(userInfo){
        //推送信息
        NSLog(@"----推送消息001");
        [self PayInfoPayContent:userInfo];
        if (application.applicationState == UIApplicationStateActive) {
            application.applicationIconBadgeNumber=0;
        }else{
            application.applicationIconBadgeNumber+=1;
        }
    }
    [self initCloudPush]; //阿里云推送
    [self registerAPNS:application]; //注册苹果推送
    [CloudPushSDK sendNotificationAck:launchOptions];  //推送通知处理
    [self registerMessageReceive]; //推送消息处理
    [self getNotificationSettingStatus];  //ios10推送通知处理
    return YES;
}
#pragma mark 推送通知跳转
- (void)pushVC:(NSDictionary *)params {
    // 类名
    NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];
    const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];
    // 从一个字串返回一个类
    Class newClass = objc_getClass(className);
    if (!newClass) {
        // 创建一个类
        Class superClass = [NSObject class];
        newClass = objc_allocateClassPair(superClass, className, 0);
        // 注册你创建的这个类
        objc_registerClassPair(newClass);
    }
    // 创建对象
    id instance = [[newClass alloc] init];
    // 对该对象赋值属性
    NSDictionary * propertys = params[@"property"];
    [propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
     {
         // 检测这个对象是否存在该属性
         if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) {
             // 利用kvc赋值
             [instance setValue:obj forKey:key];
         }
     }];
    
    
    //具体根据项目使用的导航控制器
    
    //获取导航控制器
    UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
    UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex];
    // 跳转到对应的控制器
    [pushClassStance pushViewController:instance animated:YES];
    
//    // 获取导航控制器
//    UINavigationController *pushClassStance = (UINavigationController *)self.window.rootViewController;
//    // 跳转到对应的控制器
//    [pushClassStance pushViewController:instance animated:YES];
    
}
- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName {
    unsigned int outCount, i;
    // 获取对象里的属性列表
    objc_property_t * properties = class_copyPropertyList([instance class], &outCount);
    for (i = 0; i < outCount; i++) {
        objc_property_t property =properties[i];
        // 属性名转成字符串
        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        // 判断该属性是否存在
        if ([propertyName isEqualToString:verifyPropertyName]) {
            free(properties); return YES;
        }
    }
    free(properties);
    return NO;
}

dome效果github地址

你可能感兴趣的:(iOS-集成阿里云移动推送,跳转任意界面)