- (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 推送通知跳轉(zhuǎn)
- (void)pushVC:(NSDictionary *)params {
// 類名
NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];
const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];
// 從一個字串返回一個類
Class newClass = objc_getClass(className);
if (!newClass) {
// 創(chuàng)建一個類
Class superClass = [NSObject class];
newClass = objc_allocateClassPair(superClass, className, 0);
// 注冊你創(chuàng)建的這個類
objc_registerClassPair(newClass);
}
// 創(chuàng)建對象
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];
}
}];
//具體根據(jù)項目使用的導(dǎo)航控制器
//獲取導(dǎo)航控制器
UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex];
// 跳轉(zhuǎn)到對應(yīng)的控制器
[pushClassStance pushViewController:instance animated:YES];
// // 獲取導(dǎo)航控制器
// UINavigationController *pushClassStance = (UINavigationController *)self.window.rootViewController;
// // 跳轉(zhuǎn)到對應(yīng)的控制器
// [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];
// 屬性名轉(zhuǎn)成字符串
NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
// 判斷該屬性是否存在
if ([propertyName isEqualToString:verifyPropertyName]) {
free(properties); return YES;
}
}
free(properties);
return NO;
}
dome效果github地址