//
|
// AppDelegate.m
|
// MIduo
|
//
|
// Created by apple on 17/2/20.
|
// Copyright © 2017年 yeshi. All rights reserved.
|
//
|
|
#import "AppDelegate.h"
|
|
//#import "XGPush.h" //信鸽
|
//#import "XGSetting.h"
|
#import <UserNotifications/UserNotifications.h>
|
|
#import "BaseNavigationController.h"
|
#import "NEWHomeViewController.h"
|
#import "classificationViewController.h"
|
#import "shoppingCartViewController.h"
|
#import "DynamicViewController.h"
|
#import "MineViewController.h"
|
#import "MainInviteViewController.h"
|
|
#import <ShareSDK/ShareSDK.h>
|
#import <ShareSDKConnector/ShareSDKConnector.h>
|
|
//腾讯开放平台(对应QQ和QQ空间)SDK头文件
|
#import <TencentOpenAPI/TencentOAuth.h>
|
#import <TencentOpenAPI/QQApiInterface.h>
|
|
//微信SDK头文件
|
#import "WXApi.h"
|
|
//新浪微博SDK头文件
|
#import "WeiboSDK.h"
|
|
//#import "MiPushSDK.h"
|
#import <UserNotifications/UserNotifications.h>
|
|
#import <WeexSDK/WXSDKInstance.h>
|
#import <WeexSDK/WeexSDK.h>
|
|
#import "WXAppConfiguration.h"
|
#import "WXSDKEngine.h"
|
#import "WXLog.h"
|
#import "SJModule.h"
|
#import "SJNComponet.h"
|
#import "WXImgLoaderDefaultImpl.h"
|
//#import "WXNavigationDefaultImpl.h"
|
|
/****** Weex ******/
|
// SDK
|
#import <WeexSDK/WeexSDK.h>
|
// Module
|
#import "WXUserModule.h"
|
#import "WXUtilModule.h"
|
// Component
|
#import "WXCutomNewStrategyComponent.h"
|
|
@interface AppDelegate ()<UNUserNotificationCenterDelegate,UITabBarControllerDelegate,WXApiDelegate>
|
|
@end
|
|
@implementation AppDelegate
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
// Override point for customization after application launch.
|
|
//阿里百川
|
[self setAliTrade];
|
|
//清空角标
|
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
|
|
//设置tabBar的字体颜色
|
[self setTabBarItemFontColor];
|
|
//配置
|
[self Configuration];
|
|
//监听网络
|
[self netWorkChangeEvent];
|
|
//weex
|
[self WeexInit];
|
|
//友盟
|
[self setUmeng];
|
[UMConfigure setLogEnabled:YES];
|
|
//配置客户端信息
|
[self getInfoFromCompany];
|
|
//微信登录
|
[self WeiXinChatLogin];
|
[self loadViews];
|
|
|
NSDictionary * userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
if(userInfo){
|
_isLaunch=YES;
|
// [self loginDeviceToken];
|
if(iOS10){
|
[NSTimer scheduledTimerWithTimeInterval:1.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
|
|
}];
|
}
|
}
|
|
[SVProgressHUD setMinimumDismissTimeInterval:2.0];
|
|
|
[ShareSDK registerActivePlatforms:@[@(SSDKPlatformTypeSinaWeibo),
|
@(SSDKPlatformTypeMail),
|
@(SSDKPlatformTypeSMS),
|
@(SSDKPlatformTypeCopy),
|
@(SSDKPlatformTypeWechat),
|
@(SSDKPlatformTypeQQ),
|
@(SSDKPlatformTypeRenren),
|
@(SSDKPlatformTypeFacebook),
|
@(SSDKPlatformTypeTwitter),
|
@(SSDKPlatformTypeGooglePlus)
|
]
|
onImport:^(SSDKPlatformType platformType)
|
{
|
switch (platformType)
|
{
|
case SSDKPlatformTypeWechat:
|
[ShareSDKConnector connectWeChat:[WXApi class]];
|
break;
|
case SSDKPlatformTypeQQ:
|
[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
|
break;
|
case SSDKPlatformTypeSinaWeibo:
|
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
|
|
break;
|
default:
|
break;
|
}
|
}
|
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
|
{
|
/* //友盟分享
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx5c0d167c6e3ad726" appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d" redirectURL:nil];//微信
|
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106259063" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//QQ
|
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3403499693" appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];//新浪*/
|
switch (platformType)
|
{
|
case SSDKPlatformTypeSinaWeibo:
|
//设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
|
[appInfo SSDKSetupSinaWeiboByAppKey:@"3403499693"
|
appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce"
|
redirectUri:@"https://sns.whalecloud.com/sina2/callback"
|
authType:SSDKAuthTypeBoth];
|
break;
|
case SSDKPlatformTypeWechat:
|
[appInfo SSDKSetupWeChatByAppId:@"wx5c0d167c6e3ad726"
|
appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d"];
|
break;
|
case SSDKPlatformTypeQQ:
|
[appInfo SSDKSetupQQByAppId:@"1106259063"
|
appKey:@"aed9b0303e3ed1e27bae87c33761161d"
|
authType:SSDKAuthTypeBoth];
|
break;
|
default:
|
break;
|
}
|
}];
|
|
//点击首页的tabbarItem,回到顶部
|
UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
|
|
baseTabBar.delegate=self;
|
|
if (IOS_VERSION >= 10.0) {
|
|
UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
|
|
[center setDelegate:self];
|
|
UNAuthorizationOptions type = UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionAlert;
|
|
[center requestAuthorizationWithOptions:type completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
if (granted) {
|
|
ALLog(@"注册成功");
|
|
}else{
|
|
ALLog(@"注册失败");
|
}
|
}];
|
|
} else if (IOS_VERSION >= 8.0) {
|
|
UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge |
|
|
UIUserNotificationTypeSound |
|
|
UIUserNotificationTypeAlert;
|
|
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
|
|
[application registerUserNotificationSettings:settings];
|
|
} else {// ios8以下
|
|
UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge |
|
|
UIRemoteNotificationTypeSound |
|
|
UIRemoteNotificationTypeAlert;
|
|
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];
|
}
|
//
|
// if (launchOptions) {
|
// 获取推送通知定义的userinfo
|
// UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
|
// NSString *controller = notification.userInfo[@"controller"];
|
// 这里就是告诉程序我要跳转到哪里
|
// [YTHsharedManger startManger].infomation = userInfo;
|
// [[NSNotificationCenter defaultCenter] postNotification:notification];
|
// [[NSNotificationCenter defaultCenter] postNotificationName:@"pushInfomation" object:userInfo];
|
// }
|
|
// 注册获得device Token
|
[application registerForRemoteNotifications];
|
|
return YES;
|
}
|
|
#pragma mark --- Weex初始化配置 ---
|
- (void)WeexInit {
|
|
// business configuration
|
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
|
[WXAppConfiguration setAppGroup:@"AliApp"];
|
[WXAppConfiguration setAppName:app_Name];
|
[WXAppConfiguration setAppVersion:app_Version];
|
|
// init sdk environment
|
[WXSDKEngine initSDKEnvironment];
|
|
// register custom module and component,optional
|
[WXSDKEngine registerComponent:@"navgation" withClass:[SJNComponet class]];
|
[WXSDKEngine registerComponent:@"topMenu" withClass:[WXCutomNewStrategyComponent class]];
|
|
// [WXSDKEngine registerModule:@"event" withClass:[SJModule class]];
|
[WXSDKEngine registerModule:@"userModule" withClass:[WXUserModule class]];
|
[WXSDKEngine registerModule:@"utilModule" withClass:[WXUtilModule class]];
|
|
// register the implementation of protocol, optional
|
[WXSDKEngine registerHandler:[WXImgLoaderDefaultImpl new] withProtocol:@protocol(WXImgLoaderProtocol)];
|
|
// 设置日志级别
|
[WXLog setLogLevel:WXLogLevelError];
|
}
|
|
- (void)loginDeviceToken {
|
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
|
[dic setObject:[YTHsharedManger startManger].deviceToken forKey:@"deviceToken"];
|
[dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
|
|
[JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/uidBindDeviceToken"] param:dic success:^(NSDictionary *object) {
|
NSLog(@"%@",object);
|
} fail:^(id object) {
|
NSLog(@"%@",object);
|
}];
|
}
|
- (void)loadViews {
|
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
self.window.backgroundColor=[UIColor whiteColor];
|
[self.window makeKeyAndVisible];
|
NEWHomeViewController *recommendVC = [[NEWHomeViewController alloc]init];
|
recommendVC.tabBarItem.title = @"精选";
|
recommendVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Home点击"];
|
recommendVC.tabBarItem.image = [UIImage imageNamed:@"Home"];
|
BaseNavigationController *nrecommendVC = [[BaseNavigationController alloc]initWithRootViewController:recommendVC];
|
|
classificationViewController *subVC = [[classificationViewController alloc]init];
|
subVC.tabBarItem.title = @"优惠券";
|
subVC.tabBarItem.selectedImage = [UIImage imageNamed:@"优惠券点击"];
|
subVC.tabBarItem.image = [UIImage imageNamed:@"优惠券"];
|
BaseNavigationController *nsubVC = [[BaseNavigationController alloc]initWithRootViewController:subVC];
|
|
MainInviteViewController *invateVC = [[MainInviteViewController alloc]init];
|
// invateVC..image = [[UIImage imageNamed:@"邀请有奖"] ];
|
invateVC.tabBarItem.image = [[UIImage imageNamed:@"邀请有奖"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
|
invateVC.tabBarItem.imageInsets = UIEdgeInsetsMake(3, 0, -3, 0);
|
BaseNavigationController *ninvateVC = [[BaseNavigationController alloc]initWithRootViewController:invateVC];
|
|
// shoppingCartViewController *disVC = [[shoppingCartViewController alloc]init];
|
// disVC.tabBarItem.title = @"购物车";
|
// disVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Cart点击"];
|
// disVC.tabBarItem.image = [UIImage imageNamed:@"Cart"];
|
// BaseNavigationController *ndisVC = [[BaseNavigationController alloc]initWithRootViewController:disVC];
|
// DynamicViewController
|
DynamicViewController *disVC = [[DynamicViewController alloc]init];
|
disVC.tabBarItem.title = @"动态";
|
disVC.tabBarItem.selectedImage = [UIImage imageNamed:@"动态2"];
|
disVC.tabBarItem.image = [UIImage imageNamed:@"动态"];
|
BaseNavigationController *ndisVC = [[BaseNavigationController alloc]initWithRootViewController:disVC];
|
|
MineViewController *mineVC = [[MineViewController alloc]init];
|
mineVC.tabBarItem.title = @"我的";
|
mineVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Profile点击"];
|
mineVC.tabBarItem.image = [UIImage imageNamed:@"Profile"];
|
BaseNavigationController *nmineVC = [[BaseNavigationController alloc]initWithRootViewController:mineVC];
|
|
UITabBarController *tabBarController = [[UITabBarController alloc]init];
|
// SJTabbar *tabbar = [[SJTabbar alloc]init];
|
// tabBarController.tabBar = tabbar;
|
[[UITabBar appearance] setBackgroundColor:XYRBackgroundColor];
|
tabBarController.viewControllers = @[nrecommendVC,nsubVC,ninvateVC,ndisVC,nmineVC];
|
tabBarController.tabBar.tintColor = YTHColor(229, 0, 92);
|
|
NSMutableDictionary *attr3=[NSMutableDictionary dictionary];
|
attr3[NSFontAttributeName]=[UIFont systemFontOfSize:10];
|
[[UITabBarItem appearance]setTitleTextAttributes:attr3 forState:UIControlStateNormal];
|
|
self.window.rootViewController = tabBarController;
|
|
if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]!=nil){
|
[self getMessage];
|
}
|
}
|
- (void)getMessage{
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
|
|
[dic setObject:@"1" forKey:@"page"];
|
[dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
|
|
[JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"customer/findAccountMessageList"]
|
param:dic
|
success:^(NSDictionary *object) {
|
|
ALLog(@"%@",object);
|
// NSInteger code = [object[@"code"]integerValue];
|
NSDictionary *dic = object[@"data"];
|
NSArray *array = dic[@"list"];
|
BOOL bor = NO;
|
for (NSInteger index = 0; index < array.count; index ++) {
|
NSDictionary *dic = array[index];
|
if (![dic[@"isOpen"]boolValue]) {
|
bor = YES;
|
break;
|
}
|
}
|
if (bor) {
|
UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
|
[baseTabBar.tabBar showBadgeOnItemIndex:3];
|
}else{
|
UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
|
[baseTabBar.tabBar hideBadgeOnItemIndex:3];
|
}
|
|
} fail:^(id object) {
|
NSLog(@"%@",object);
|
}];
|
}
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
|
|
// 新接口写法
|
if (![[AlibcTradeSDK sharedInstance] application:application
|
openURL:url
|
options:options]) {
|
//处理其他app跳转到自己的app,如果百川处理过会返回YES
|
return [WXApi handleOpenURL:url delegate:self];
|
}
|
|
|
return 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 invalidate graphics rendering callbacks. 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.
|
|
|
}
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
|
[self boardCheck];
|
|
if ([YTHsharedManger startManger].isEnterForeground) {
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"isEnterForeground" object:nil];
|
}
|
}
|
|
#pragma mark --- 查看粘贴板 ---
|
- (void)boardCheck {
|
|
UIPasteboard *board = [UIPasteboard generalPasteboard];
|
|
if (board.string != nil) {
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GUESSYOULIKE" object:board.string];
|
UIPasteboard*pasteboard = [UIPasteboard generalPasteboard];
|
pasteboard.string=@"";
|
}
|
}
|
|
- (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.
|
}
|
|
//获取当前屏幕显示的viewcontroller
|
- (UIViewController *)getCurrentVC{
|
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
|
return currentVC;
|
}
|
|
- (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC{
|
UIViewController *currentVC;
|
|
if ([rootVC presentedViewController]) {
|
// 视图是被presented出来的
|
rootVC = [rootVC presentedViewController];
|
}
|
if ([rootVC isKindOfClass:[UITabBarController class]]) {
|
// 根视图为UITabBarController
|
currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
|
} else if ([rootVC isKindOfClass:[UINavigationController class]]){
|
// 根视图为UINavigationController
|
currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
|
} else {
|
// 根视图为非导航类
|
currentVC = rootVC;
|
}
|
|
return currentVC;
|
}
|
|
//原生
|
-(void)WeiXinChatLogin{
|
[WXApi registerApp:@"wx5c0d167c6e3ad726"];
|
}
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
}
|
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
|
|
if (![[AlibcTradeSDK sharedInstance] application:application
|
openURL:url
|
sourceApplication:sourceApplication
|
annotation:annotation]) {
|
// 处理其他app跳转到自己的app
|
}
|
|
//该URL是否已经被SDK处理过
|
if ([[ALBBSDK sharedInstance] isTBBackUrl:url.absoluteString]) {
|
[[ALBBSDK sharedInstance] loginByURL:url];
|
|
//开发者继续自己处理
|
[[ALBBSDK sharedInstance] setLoginResultHandler:^(ALBBSession *session) {
|
if(session.isLogin){
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TaoBaoLogin"];
|
}else{
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"TaoBaoLogin"];
|
}
|
}];
|
}
|
|
//友盟分享
|
BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
|
if (result) {
|
return result;
|
}
|
|
return [WXApi handleOpenURL:url delegate:self];
|
}
|
|
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
|
return [WXApi handleOpenURL:url delegate:self];
|
}
|
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
//NSString *accountStr=[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
|
|
NSString *deviceTokenStr = [[[[deviceToken description]
|
|
stringByReplacingOccurrencesOfString:@"<" withString:@""]
|
|
stringByReplacingOccurrencesOfString:@">" withString:@""]
|
|
stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|
NSLog(@"deviceTokenStr:\n%@",deviceTokenStr);
|
[YTHsharedManger startManger].deviceToken = deviceTokenStr;
|
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
|
|
[dic setObject:deviceTokenStr forKey:@"deviceToken"];
|
|
NSLog(@"%@",[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/insertDeviceToken"]);
|
[JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/insertDeviceToken"] param:dic success:^(NSDictionary *object) {
|
NSLog(@"%@",object);
|
// NSInteger code = [object[@"code"]integerValue];
|
// [self.datasource removeAllObjects];
|
|
} fail:^(id object) {
|
NSLog(@"%@",object);
|
}];
|
if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]!=nil){
|
[self loginDeviceToken];
|
|
}
|
}
|
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
|
{
|
// 注册APNS失败
|
// 自行处理
|
NSLog(@"%@",err);
|
}
|
|
/**
|
收到通知的回调
|
|
@param application UIApplication 实例
|
@param userInfo 推送时指定的参数
|
*/
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
// UIApplicationStateActive 应用程序处于前台
|
NSLog(@"%@",userInfo);
|
if(application.applicationState == UIApplicationStateActive){
|
|
//程序当前正处于前台
|
//发送本地通知
|
NSTimeInterval nowtime = [[NSDate date] timeIntervalSince1970];
|
NSInteger theTime = [[NSNumber numberWithDouble:nowtime] unsignedIntegerValue];
|
[self registerLocalNotification:(int)theTime alertBody:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] userDict:userInfo];
|
}
|
// UIApplicationStateBackground 应用程序在后台,用户从通知中心点击消息将程序从后台调至前台
|
if(application.applicationState == UIApplicationStateBackground){
|
|
}
|
}
|
|
/**
|
收到本地通知的回调
|
|
@param application UIApplication 实例
|
*/
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notifications{
|
if(application.applicationState == UIApplicationStateActive){
|
//程序当前正处于前台
|
|
}else{
|
|
}
|
}
|
|
/**
|
收到静默推送的回调
|
|
@param application UIApplication 实例
|
@param userInfo 推送时指定的参数
|
@param completionHandler 完成回调
|
*/
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
NSLog(@"[XGDemo] userinfo %@", userInfo);
|
if(application.applicationState == UIApplicationStateActive){
|
//程序当前正处于前台
|
//发送本地通知
|
NSTimeInterval nowtime = [[NSDate date] timeIntervalSince1970];
|
NSInteger theTime = [[NSNumber numberWithDouble:nowtime] unsignedIntegerValue];
|
[self registerLocalNotification:theTime alertBody:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] userDict:userInfo];
|
}
|
if(application.applicationState == UIApplicationStateBackground){
|
//程序当前正处于后台
|
}
|
completionHandler(UIBackgroundFetchResultNewData);
|
}
|
|
// iOS 10 新增 API
|
// iOS 10 会走新 API, iOS 10 以前会走到老 API
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
// App 用户点击通知的回调
|
// 无论本地推送还是远程推送都会走这个回调
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
|
NSLog(@"[XGDemo] click notification");
|
NSDictionary * userInfo = response.notification.request.content.userInfo;
|
[YTHsharedManger startManger].infomation = userInfo;
|
// [[NSNotificationCenter defaultCenter] postNotification:notification];
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushInfomation" object:userInfo];
|
|
completionHandler();
|
}
|
|
// App 在前台弹通知需要调用这个接口
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
|
|
//NSDictionary * userInfo = notification.request.content.userInfo;
|
|
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
|
// [MiPushSDK handleReceiveRemoteNotification:userInfo];
|
}
|
// completionHandler(UNNotificationPresentationOptionAlert);
|
|
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
|
}
|
#endif
|
|
- (void)registerLocalNotification:(NSInteger)alertTime alertBody:(NSString *)alertBody userDict:(NSDictionary *)userDict
|
{
|
UILocalNotification *notification = [[UILocalNotification alloc] init];
|
// 设置触发通知的时间
|
NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
|
|
notification.fireDate = fireDate;
|
// 时区
|
notification.timeZone = [NSTimeZone defaultTimeZone];
|
|
// 通知内容
|
notification.alertBody = alertBody;
|
notification.applicationIconBadgeNumber++;
|
// 通知被触发时播放的声音
|
notification.soundName = UILocalNotificationDefaultSoundName;
|
// 通知参数
|
notification.userInfo = userDict;
|
|
//请求本地通知 授权
|
[self getRequestWithLocalNotificationSleep:notification];
|
}
|
|
- (void)getRequestWithLocalNotificationSleep:(UILocalNotification *)notification
|
{
|
// ios8后,需要添加这个注册,才能得到授权
|
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
|
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
|
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
|
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
|
}
|
|
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
|
}
|
|
/**
|
tabBarItem的字体颜色设置
|
*/
|
-(void)setTabBarItemFontColor {
|
// 字体颜色 (选中)
|
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0F], NSForegroundColorAttributeName : YTHColor(229, 0, 92)} forState:UIControlStateSelected];
|
|
// 字体颜色 (未选中)
|
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0F], NSForegroundColorAttributeName:YTHColor(139, 139, 139)} forState:UIControlStateNormal];
|
}
|
|
/**
|
配置
|
*/
|
-(void)Configuration {
|
//设置状态栏的颜色
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
|
|
//防止横屏时,状态栏被隐藏
|
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
|
|
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
|
|
//去黑线
|
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
|
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
|
|
}
|
|
/**
|
* 配置客户端信息
|
*/
|
-(void)getInfoFromCompany {
|
//判断之前是否缓存了用户信息
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
if ([fileManager fileExistsAtPath:USERINFOfILE]){
|
NSDictionary *userInfo=[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:USERINFOfILE]];
|
[[NSUserDefaults standardUserDefaults] setObject:[userInfo objectForKey:@"id"] forKey:@"userId"];
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"newUser"];
|
}else{
|
//没有缓存用户信息,说明这是一个全新的用户
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"newUser"];
|
}
|
|
[[YTHNetInterface startInterface] getSystemClientParamsWithblock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSUserDefaults *uid = [NSUserDefaults standardUserDefaults];
|
NSArray *tempArr=[[result objectForKey:@"data"] objectForKey:@"systemClientParamsList"];
|
for (int i=0; i<tempArr.count; i++) {
|
NSDictionary *tempDic=tempArr[i];
|
[uid setObject:[tempDic objectForKey:@"value"] forKey:[tempDic objectForKey:@"key"]];
|
}
|
[uid synchronize];
|
}else{
|
|
}
|
}];
|
}
|
|
#pragma mark 阿里百川
|
-(void)setAliTrade {
|
// 百川平台基础SDK初始化,加载并初始化各个业务能力插件
|
[[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
|
NSLog(@"成功");
|
} failure:^(NSError *error) {
|
NSLog(@"Init failed: %@", error.description);
|
}];
|
|
// 开发阶段打开日志开关,方便排查错误信息
|
//默认调试模式打开日志,release关闭,可以不调用下面的函数
|
[[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
|
|
// 配置全局的淘客参数
|
//如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
|
AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
|
taokeParams.pid = FanLi_Pid; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
|
taokeParams.adzoneId = FanLi_adzoneId;
|
taokeParams.extParams=@{@"taokeAppkey":@"24838852"};
|
|
[[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
|
|
// 设置全局配置,是否强制使用h5
|
[[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
|
}
|
|
/**
|
注册推送
|
*/
|
- (void)registerAPNS {
|
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
if (sysVer >= 10) {
|
// iOS 10
|
[self registerPush10];
|
} else if (sysVer >= 8) {
|
// iOS 8-9
|
[self registerPush8to9];
|
} else {
|
// before iOS 8
|
[self registerPushBefore8];
|
}
|
#else
|
if (sysVer < 8) {
|
// before iOS 8
|
[self registerPushBefore8];
|
} else {
|
// iOS 8-9
|
[self registerPush8to9];
|
}
|
#endif
|
}
|
|
/**
|
iOS10注册通知的方法
|
*/
|
- (void)registerPush10 {
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
center.delegate = self;
|
|
[center requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
if (granted) {
|
}
|
}];
|
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
#endif
|
}
|
|
/**
|
iOS8,9注册通知的方法
|
*/
|
- (void)registerPush8to9 {
|
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
|
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
|
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
}
|
/**
|
iOS8之前的注册通知方法
|
*/
|
- (void)registerPushBefore8 {
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED <= __IPHONE_8_0
|
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
|
#endif
|
}
|
|
#pragma mark -UITabBarControllerDelegate
|
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"HomeViewController" object:nil userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"DynamicViewController" object:nil userInfo:nil];
|
}
|
|
#pragma mark 友盟相关
|
- (void)setUmeng {
|
|
[UMConfigure initWithAppkey:UmengKey channel:nil];
|
[MobClick setScenarioType:E_UM_NORMAL];
|
|
//友盟分享
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx5c0d167c6e3ad726" appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d" redirectURL:nil];//微信
|
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106259063" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//QQ
|
|
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3403499693" appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];//新浪
|
|
}
|
|
-(void)netWorkChangeEvent {
|
|
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
|
NSURL *url = [NSURL URLWithString:@"http://baidu.com"];
|
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
|
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
self.netWorkStatesCode = status;
|
switch (status) {
|
case AFNetworkReachabilityStatusReachableViaWWAN:
|
NSLog(@"当前使用的是流量模式");
|
break;
|
case AFNetworkReachabilityStatusReachableViaWiFi:
|
NSLog(@"当前使用的是wifi模式");
|
break;
|
case AFNetworkReachabilityStatusNotReachable:
|
NSLog(@"断网了");
|
break;
|
case AFNetworkReachabilityStatusUnknown:
|
NSLog(@"变成了未知网络状态");
|
break;
|
|
default:
|
break;
|
}
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"netWorkChangeEventNotification" object:@(status)];
|
}];
|
|
[manager.reachabilityManager startMonitoring];
|
}
|
|
#pragma mark -WXApiDelegate
|
-(void)onReq:(BaseReq*)req {
|
//onReq是微信终端向第三方程序发起请求,要求第三方程序响应。第三方程序响应完后必须调用sendRsp返回。在调用sendRsp返回时,会切回到微信终端程序界面。
|
NSLog(@"%@",req);
|
|
}
|
#pragma mark 微信登录的唯一入口
|
- (void)getUserInfoResponse:(APIResponse*) response {
|
// NSDictionary *dic = @{@"appid":@""};
|
}
|
-(void)onResp:(BaseResp*)resp {
|
|
SendAuthResp *rep = (SendAuthResp *)resp;
|
|
if (rep.errCode == 0) {//登录成功
|
|
if ([YTHsharedManger startManger].isChangeWX) {
|
|
[self changeWXWithCode:rep.code];
|
|
[YTHsharedManger startManger].isChangeWX = NO;
|
|
return;
|
}
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showWithStatus:@"微信绑定中"];
|
|
if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]) {//uid已经存在,说明是绑定操作
|
|
[[YTHsharedManger startManger] bindUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]
|
WithLoginType:@"2"
|
WithOpenid:nil
|
WithWXCode:rep.code
|
WithTBName:nil block:^(BOOL isSuccessful, NSDictionary *dic) {
|
|
if (isSuccessful) {
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showSuccessWithStatus:BIND_SUCCESS];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"WeChatReload" object:nil];
|
|
} else {
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"WeChatReload" object:nil];
|
}
|
}];
|
} else {
|
|
if ([YTHsharedManger startManger].isBound) {
|
|
[[YTHsharedManger startManger] LogInForFanliQuanWithLoginType:@"2" WithWXCode:rep.code create:@"2" uid:@"0" isfirst:[YTHsharedManger startManger].isfirst block:^(BOOL isSuccessful, NSDictionary *dic) {
|
|
if (isSuccessful) {
|
|
NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
|
[tempDic setObject:@"1" forKey:@"isSuccessful"];
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showSuccessWithStatus:BIND_SUCCESS];
|
|
if ([YTHsharedManger startManger].isMessageLogin) {
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLoginMessage" object:tempDic];
|
|
} else {
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
|
}
|
|
} else {
|
|
NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithCapacity:0];
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
|
[tempDic setObject:@"0" forKey:@"isSuccessful"];
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showErrorWithStatus:BIND_FAIL];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
|
}
|
}];
|
|
} else {
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showWithStatus:@"正在为你登录..."];
|
|
[[YTHsharedManger startManger] LogInForFanliQuanWithLoginType:@"2" WithWXCode:rep.code create:@"0" uid:@"0" isfirst:[YTHsharedManger startManger].isfirst block:^(BOOL isSuccessful, NSDictionary *dic) {
|
|
if (isSuccessful) {
|
|
NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
|
[tempDic setObject:@"1" forKey:@"isSuccessful"];
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showSuccessWithStatus:LOGIN_SUCCESS];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
|
|
} else {
|
|
NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
|
[tempDic setObject:@"0" forKey:@"isSuccessful"];
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showErrorWithStatus:LOGIN_FAIL];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
|
}
|
}];
|
}
|
}
|
}
|
}
|
|
- (void)changeWXWithCode:(NSString *)code {
|
|
NSDictionary *dic = [[NSMutableDictionary alloc] init];
|
|
[dic setValue:code forKey:@"code"];
|
[dic setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
|
|
[JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"/user/changeWX"] param:dic success:^(NSDictionary *object) {
|
|
if ([object[@"code"]integerValue] == 0) {
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showSuccessWithStatus:BIND_CHANGE_SUCCESS];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:object[@"data"][@"user"]];
|
|
} else {
|
|
[SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
|
[SVProgressHUD showSuccessWithStatus:object[@"msg"]];
|
}
|
|
} fail:^(id object) {
|
|
[SVProgressHUD showSuccessWithStatus:object];
|
}];
|
}
|
|
-(void)dealloc {
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
name:@"netWorkChangeEventNotification"
|
object:nil];
|
}
|
|
@end
|