//
|
// AppDelegate.m
|
// BaseProject
|
//
|
// Created by WindShan on 2016/12/5.
|
// Copyright © 2016年 WindShan. All rights reserved.
|
//
|
|
#import "AppDelegate.h"
|
|
// test page
|
#import "NetworkTestPage.h"
|
#import "MJExampleViewController.h"
|
#import "SegmentedPage.h"
|
#import "CommonReqModel.h"
|
#import "NetworkSingleton.h"
|
#import "UserModel.h"
|
#import "LoginPage.h"
|
#import "HomePage.h"
|
#import "SegmentedPage.h"
|
|
#import "CBMoralManager.h"
|
#import "SettingPage.h"
|
#import "PhotosPage.h"
|
#import "MinePage.h"
|
#import "DITableViewController.h"
|
#import "RadiaDetectionPage.h"
|
#import "HistoryRecordPage.h"
|
|
@interface AppDelegate ()
|
{
|
NSMutableArray *notifyingCharacteristicsArray;
|
}
|
|
@property (nonatomic) Reachability *hostReachability;
|
@property (nonatomic) Reachability *internetReachability;
|
|
|
@end
|
|
@implementation AppDelegate
|
|
|
|
+ (AppDelegate *)AppInstance;
|
{
|
return (AppDelegate *)[UIApplication sharedApplication].delegate;
|
}
|
|
- (void)showHomePage
|
{
|
|
HomePage *page = [[HomePage alloc] init];
|
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
self.window.backgroundColor = [UIColor whiteColor];
|
self.window.rootViewController = page;
|
|
[self.window makeKeyAndVisible];
|
}
|
|
- (void)showHomePage2
|
{
|
// 单页
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
// Override point for customization after application launch.
|
self.window.backgroundColor = [UIColor whiteColor];
|
HistoryRecordPage *root = [[HistoryRecordPage alloc]init];
|
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:root];//先将root添加在navigation上
|
nav.navigationBarHidden = YES;
|
[self.window setRootViewController:nav];//navigation加在window上
|
|
[self.window makeKeyAndVisible];
|
}
|
|
- (void)showLoginPage
|
{
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
// Override point for customization after application launch.
|
self.window.backgroundColor = [UIColor whiteColor];
|
LoginPage *root = [[LoginPage alloc]init];
|
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:root];//先将root添加在navigation上
|
nav.navigationBarHidden = YES;
|
[self.window setRootViewController:nav];//navigation加在window上
|
[self.window makeKeyAndVisible];
|
}
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
{
|
|
/*
|
Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the method reachabilityChanged will be called.
|
*/
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
|
|
//Change the host name here to change the server you want to monitor.
|
|
// 要使用百度地图,请先启动BaiduMapManager
|
self.mapManager = [[BMKMapManager alloc]init];
|
BOOL ret = [self.mapManager start:@"ZiqQxvKGjZVNbITouYn7dIwDjb1CbKcy" generalDelegate:self];
|
if (!ret) {
|
NSLog(@"manager start failed!");
|
}
|
|
// 添加网络监听
|
self.hostReachability = [Reachability reachabilityWithHostName:@"www.baidu.com"];
|
[self.hostReachability startNotifier];
|
[self updateInterfaceWithReachability:self.hostReachability];
|
self.internetReachability = [Reachability reachabilityForInternetConnection];
|
[self.internetReachability startNotifier];
|
[self updateInterfaceWithReachability:self.internetReachability];
|
|
|
|
[self showLoginPage];
|
|
//异常对象:NSException
|
//参数:将函数的地址给它
|
NSSetUncaughtExceptionHandler(&getException);
|
|
// Override point for customization after application launch.
|
return YES;
|
}
|
|
/*!
|
* Called by Reachability whenever status changes.
|
*/
|
- (void) reachabilityChanged:(NSNotification *)note
|
{
|
Reachability* curReach = [note object];
|
NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
|
[self updateInterfaceWithReachability:curReach];
|
}
|
|
|
- (void)updateInterfaceWithReachability:(Reachability *)reachability
|
{
|
if (reachability == self.hostReachability)
|
{
|
NetworkStatus netStatus = [reachability currentReachabilityStatus];
|
BOOL connectionRequired = [reachability connectionRequired];
|
|
NSString* baseLabelText = @"";
|
|
if (connectionRequired)
|
{
|
baseLabelText = NSLocalizedString(@"Cellular data network is available.\nInternet traffic will be routed through it after a connection is established.", @"Reachability text if a connection is required");
|
}
|
else
|
{
|
baseLabelText = NSLocalizedString(@"Cellular data network is active.\nInternet traffic will be routed through it.", @"Reachability text if a connection is not required");
|
}
|
|
switch (netStatus)
|
{
|
case NotReachable:
|
|
break;
|
|
default:
|
break;
|
}
|
BASE_INFO_FUN(baseLabelText);
|
}
|
|
}
|
|
- (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.
|
|
if (!notifyingCharacteristicsArray)
|
{
|
notifyingCharacteristicsArray = [NSMutableArray array];
|
}
|
|
/* Stop notification of characteristics while enter in background */
|
for (CBService *service in [[CBMoralManager sharedManager] foundServices])
|
{
|
for (CBCharacteristic *characteristic in service.characteristics)
|
{
|
if (characteristic.isNotifying && ![characteristic.UUID isEqual:BOOT_LOADER_CHARACTERISTIC_UUID])
|
{
|
[[[CBMoralManager sharedManager] myPeripheral] setNotifyValue:NO forCharacteristic:characteristic];
|
[notifyingCharacteristicsArray addObject:characteristic];
|
}
|
}
|
|
}
|
}
|
|
|
- (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.
|
|
/* Enable notification of characteristics while enter in foreground */
|
|
if (notifyingCharacteristicsArray)
|
{
|
for (CBCharacteristic *characteristic in notifyingCharacteristicsArray)
|
{
|
if (![characteristic.UUID isEqual:BOOT_LOADER_CHARACTERISTIC_UUID])
|
{
|
[[[CBMoralManager sharedManager] myPeripheral] setNotifyValue:YES forCharacteristic:characteristic];
|
}
|
}
|
}
|
}
|
|
|
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
|
{
|
NSLog(@"Registered to receive local notification...");
|
}
|
|
- (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.
|
}
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
}
|
|
//获得异常的C函数
|
void getException(NSException *exception)
|
{
|
NSLog(@"名字:%@",exception.name);
|
NSLog(@"原因:%@",exception.reason);
|
NSLog(@"用户信息:%@",exception.userInfo);
|
NSLog(@"栈内存地址:%@",exception.callStackReturnAddresses);
|
NSLog(@"栈描述:%@",exception.callStackSymbols);
|
//每次启动的时候将,捕获的异常信息,反馈给服务器
|
//获取当前设备
|
UIDevice*divice=[UIDevice currentDevice];
|
//1.系统版本
|
NSString*systemVersion=divice.systemVersion;
|
//2.app当前版本
|
//先获取当前infoplist文件数据
|
NSDictionary*infoDic=[[NSBundle mainBundle] infoDictionary];
|
//然后从字典中取出版本号
|
NSString*version=[infoDic objectForKey:@"CFBundleShortVersionString"];
|
NSLog(@"系统版本%@",version);
|
//3.系统时间
|
NSDate*date=[NSDate date];
|
//4.设备种类
|
NSString*model=divice.model;
|
//将捕获的异常数据进行保存,保存到本地
|
//可以在下一次启动的时候将数据发给服务器
|
}
|
|
-(void)getUserInfo
|
{
|
|
//[UserDefault stringForKey:@"user_id"]
|
NSString *path = [[NSString alloc] initWithFormat:USER_GETINFO];
|
|
CommonReqModel * model = [[CommonReqModel alloc] init];
|
model.phone = [UserDefault stringForKey:@"phone"];
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody)
|
{
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
if(resModel.code == 0)
|
{
|
//发送成功提示
|
if(![Global isEmptyObject:resModel.content])
|
{
|
// 成功处理
|
_loginUser = [resModel.content mutableCopy];
|
|
UserModel * userModel = [UserModel mj_objectWithKeyValues:resModel.content];
|
|
// 存储用户信息
|
[UserDefault setObject:@"1" forKey:@"isLogin"];
|
[UserDefault setObject:userModel._id forKey:@"user_id"];
|
[UserDefault setObject:userModel.phone forKey:@"phone"];
|
[UserDefault setObject:userModel.password forKey:@"password"];
|
[UserDefault setObject:userModel.nickname forKey:@"nickname"];
|
[UserDefault setObject:userModel.refresh_frequency forKey:@"refresh_frequency"];
|
[UserDefault setObject:userModel.is_open_upload forKey:@"is_open_upload"];
|
[UserDefault setObject:userModel.video forKey:@"video"];
|
[UserDefault synchronize];//使用synchronize强制立即将数据写入磁盘,防止在写完NSUserDefaults后程序退出导致的数据丢失
|
|
// 跳转主界面
|
[GetAppDelegate showHomePage];
|
}
|
else
|
{
|
// 出错处理
|
[UserDefault setObject:@"0" forKey:@"isLogin"];
|
}
|
|
}
|
else
|
{
|
[UserDefault setObject:@"0" forKey:@"isLogin"];
|
//[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
[UserDefault setObject:@"0" forKey:@"isLogin"];
|
//[Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
|
}
|
|
|
@end
|