123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #import "AppDelegate.h"
- #import "TabBarController.h"
- #import "WorkFlowTabbarController.h"
- #import "WXApi.h"
- #import "HKFloatManager.h"
- @interface AppDelegate ()<JPUSHRegisterDelegate,WXApiDelegate>
- @property (nonatomic, strong) TabBarController *tabBar;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- self.tabBar = [TabBarController sharedTabBarController];
- [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
- [[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];
-
-
- [self configUSharePlatforms];
-
- [[EaseSDKHelper shareHelper] hyphenateApplication:application appkey:kHuanXinAppKey apnsCertName:kHuanXinApnsName];
-
- [WXApi registerApp:wxAppKey universalLink:@"https://apk.tederen.com"];
- [self settingPush: launchOptions];
- if (![UserManager checkStringNull:kToken]){
- [[EMClient sharedClient] logout:YES completion:^(EMError *aError) {
- NSData * data = USERDEFAULTSGET(@"USERINFO");
- AppUserModel * model = (AppUserModel*) [NSKeyedUnarchiver unarchiveObjectWithData:data];
- [[EaseSDKHelper shareHelper] loginEaseWithUsername:model.ImId password:@"123456"];
- }];
- self.window.rootViewController = self.tabBar;
- }else{
- self.window.rootViewController = [StoryboardManager shared].login.instantiateInitialViewController;
- }
- [self.window makeKeyAndVisible];
-
- [HKFloatManager addFloatVcs:@[@"HKSecondViewController"]];
- return YES;
- }
- - (void)configUSharePlatforms
- {
- [UMConfigure initWithAppkey:UMengAppKey channel:nil];
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:wxAppKey appSecret:wxAppSecret redirectURL:@"http://mobile.umeng.com/social"];
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatTimeLine appKey:wxAppKey appSecret:wxAppSecret redirectURL:@"http://mobile.umeng.com/social"];
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:QQAppKey appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:WBAppKey appSecret:WBAppSecret redirectURL:@"http://mobile.umeng.com/social"];
- }
- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
- {
- NSString * str = [url absoluteString];
- if ([str hasPrefix:@"iossmartrhino"]) {
- if (![UserManager checkStringNull:kToken]){
- str = [str substringFromIndex:20];
- NSArray *array = [str componentsSeparatedByString:@"&"];
- NSDictionary * dict= @{@"Id":array[0],@"type":array[1],@"userId":array[2],@"name":array[3],@"describe":array[4]};
- [[NSNotificationCenter defaultCenter] postNotificationName:SHARERETURNSUCCESS object:nil userInfo:dict];
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [TabBarController sharedTabBarController];
- [[TabBarController sharedTabBarController] setSelectedIndex:0];
- [window makeKeyAndVisible];
- }else{
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [StoryboardManager shared].login.instantiateInitialViewController;
- [window makeKeyAndVisible];
- }
- }
- return [WXApi handleOpenURL:url delegate:self];
- }
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
- {
- if ([url.host isEqualToString:@"oauth"]){
- return [WXApi handleOpenURL:url delegate:self];
- }
-
- NSString * str = [url absoluteString];
- if ([str hasPrefix:@"iossmartrhino"]) {
- if (![UserManager checkStringNull:kToken]){
- str = [str substringFromIndex:20];
- NSArray *array = [str componentsSeparatedByString:@"&"];
- NSDictionary * dict= @{@"Id":array[0],@"type":array[1],@"userId":array[2],@"name":array[3],@"describe":array[4]};
- [[NSNotificationCenter defaultCenter] postNotificationName:SHARERETURNSUCCESS object:nil userInfo:dict];
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [TabBarController sharedTabBarController];
- [[TabBarController sharedTabBarController] setSelectedIndex:0];
- [window makeKeyAndVisible];
- }else{
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [StoryboardManager shared].login.instantiateInitialViewController;
- [window makeKeyAndVisible];
- }
- }
- BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url options:options];
- if (!result) {
- }
- return result;
- }
- + (UINavigationController *)getRootController {
- return (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
- }
- + (UIViewController *)getTopView {
- UINavigationController *rootNavigation = [self getRootController];
- return rootNavigation.topViewController;
- }
- + (instancetype)appdelegate {
- return [UIApplication sharedApplication].delegate;
- }
- - (void)applicationWillResignActive:(UIApplication *)application {
-
-
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application {
-
-
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application {
-
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application {
-
- }
- - (void)applicationWillTerminate:(UIApplication *)application {
-
- }
- #pragma mark - 极光
- - (void)settingPush:(NSDictionary *)launchOptions {
- JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
- entity.types = JPAuthorizationOptionAlert | JPAuthorizationOptionBadge | JPAuthorizationOptionSound;
- [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
- [JPUSHService setupWithOption:launchOptions appKey:kJGAppKey
- channel:@"tederen"
- apsForProduction:YES
- advertisingIdentifier:nil];
- [JpushTool setAlias:@"18224073257" completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
-
- } seq:18224073257];
-
- }
- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- NSLog(@"%@",deviceToken);
- [JPUSHService registerDeviceToken:deviceToken];
-
- }
- - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
-
- }
- #pragma mark - JPush
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
-
- NSDictionary * userInfo = notification.request.content.userInfo;
- if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
- }
- completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
- }
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
-
- NSDictionary * userInfo = response.notification.request.content.userInfo;
- if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
-
- NSString * message = userInfo[@"aps"][@"alert"];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
- [alert addAction:sureAction];
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
- [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
- }
- completionHandler();
- }
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
-
- [JPUSHService handleRemoteNotification:userInfo];
- NSString * message = userInfo[@"aps"][@"alert"];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
- [alert addAction:sureAction];
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
- [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
- completionHandler(UIBackgroundFetchResultNewData);
- }
- #pragma mark - 微信登录
- - (void)onResp:(BaseResp *)resp{
-
-
- if ([resp isMemberOfClass:[SendAuthResp class]]) {
- NSLog(@"******************获得的微信登录授权******************");
-
- SendAuthResp *aresp = (SendAuthResp *)resp;
- if (aresp.errCode != 0 ) {
- dispatch_async(dispatch_get_main_queue(), ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- SHOWERROR(@"微信授权失败");
- });
- });
- return;
- }
-
- NSString *code = aresp.code;
- [self getWeiXinOpenId:code];
- }
- }
- - (void)getWeiXinOpenId:(NSString *)code{
-
- NSString *url =[NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code",wxAppKey,wxAppSecret,code];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSURL *zoneUrl = [NSURL URLWithString:url];
- NSString *zoneStr = [NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding error:nil];
- NSData *data1 = [zoneStr dataUsingEncoding:NSUTF8StringEncoding];
-
- if (!data1) {
- dispatch_async(dispatch_get_main_queue(), ^{
- SHOWERROR(@"微信授权失败");
- });
- return ;
- }
-
- NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data1 options:NSJSONReadingMutableContainers error:nil];
- NSLog(@"token、openID字典===%@",dic);
- if ([dic[@"openid"] length] > 0) {
- [[NSNotificationCenter defaultCenter] postNotificationName:WeiChatSuccess object:nil userInfo:dic];
- }else{
- dispatch_async(dispatch_get_main_queue(), ^{
- SHOWERROR(@"微信授权失败");
- });
- return ;
- }
- });
- }
- - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
- if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
- NSURL *webpageURL = userActivity.webpageURL;
- NSString * str = [webpageURL absoluteString];
- if ([str hasPrefix:@"iossmartrhino"]) {
- if (![UserManager checkStringNull:kToken]){
- str = [str substringFromIndex:20];
- NSArray *array = [str componentsSeparatedByString:@"&"];
- NSDictionary * dict= @{@"Id":array[0],@"type":array[1],@"userId":array[2],@"name":array[3],@"describe":array[4]};
- [[NSNotificationCenter defaultCenter] postNotificationName:SHARERETURNSUCCESS object:nil userInfo:dict];
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [TabBarController sharedTabBarController];
- [[TabBarController sharedTabBarController] setSelectedIndex:0];
- [window makeKeyAndVisible];
- }else{
- UIWindow *window = [UtilsTools getWindow];
- window.rootViewController = [StoryboardManager shared].login.instantiateInitialViewController;
- [window makeKeyAndVisible];
- }
- }
-
- }
-
- return YES;
- }
- @end
|