iOS-LYC項目總結之AppDelegate-第一部分

本文按三部分來寫,

第一部分總結下該項目用到的關于 appdelegate ?的 方法和涉及的一些功能。

第二部分主要是用于介紹下,沒有涉及的方法和功能。

第三部分,擴展一下,用到的和沒用到的功能一個部分補充。

第一部分:

先看一下總共用到了appdelegate里的哪些方法

1.程序載入后

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

//設置狀態欄顏色UIStatusBarStyleDefault = 0黑色文字,淺色背景時使UIStatusBarStyleLightContent = 1白色文字,深色背景時使用

[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];

//設置配置IQKeyboard管理者

[selfsetupIQKeyboardManager];

//設置配置分享軟件開發包Software Development Kit

[selfsetupShareSDK];

//設置jpush推送

[selfsetupJPush:launchOptions];

//請求服務器時間,和本地進行矯正

[selfreqSeverTime];

//設置根視圖

[selfsetupWindowRootViewController];

//設置崩潰日志記錄bugly software dvelopment kit.

[BuglystartWithAppId:@"XXXXXXX"];

returnYES;

}

2.applicationDidBecomeActive 應用程序掛起、復原與終止.? 英語字面意思是應用程序變得活躍時, 這個方法,主要是為了需求,給服務器一次記錄,每次都請求一次接口

- (void)applicationDidBecomeActive:(UIApplication*)application {

[[APIClientsharedManager]netReqNotify:^(NSDictionary*responseDic) {

NSLog(@"激活喚醒:%@",responseDic);

}failure:^(NSError*error) {

NSLog(@"激活喚醒:error %@",error);

}];

}

}

3.關于通知,推送 ?

//Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).

/ /告訴委托應用成功注冊蘋果推送通知服務(apn)。

- (void)application:(UIApplication*)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

/// Required -注冊DeviceToken

[JPUSHServiceregisterDeviceToken:deviceToken];

}

//Called when your app has received a remote notification.

/ /時調用應用程序遠程通知已收到。

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {

// Required,For systems with less than or equal to iOS6

[JPUSHServicehandleRemoteNotification:userInfo];

}

接收遠程通知

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {

NSIntegerbadge = [UIApplicationsharedApplication].applicationIconBadgeNumber;

if(badge >0) {

[[UIApplicationsharedApplication]setApplicationIconBadgeNumber:badge-1];

[JPUSHServicesetBadge:badge-1];

}

// IOS 7 Support Required

[JPUSHServicehandleRemoteNotification:userInfo];

completionHandler(UIBackgroundFetchResultNewData);

}


//4.關于finish 里的 setup 方法

這個管理文本框鍵盤 第三方代碼,很不錯,我這里的版本有點舊

- (void)setupIQKeyboardManager

{

IQKeyboardManager*manager = [IQKeyboardManagersharedManager];

manager.enable=YES;

manager.shouldResignOnTouchOutside=YES;

manager.shouldToolbarUsesTextFieldTintColor=YES;

manager.enableAutoToolbar=NO;

manager.toolbarManageBehaviour=IQAutoToolbarBySubviews;

}

這里的22 23 24 是分享平臺的縮寫,具體看文檔。

- (void)setupShareSDK

{

[ShareSDKregisterApp:@"XX"

activePlatforms:@[

//@(SSDKPlatformTypeSinaWeibo),

@(22),

@(23),

@(24),

@(6)

]

onImport:^(SSDKPlatformTypeplatformType)

{

switch(platformType)

{

caseSSDKPlatformTypeWechat:

[ShareSDKConnectorconnectWeChat:[WXApiclass]];

break;

caseSSDKPlatformTypeQQ:

[ShareSDKConnectorconnectQQ:[QQApiInterfaceclass]tencentOAuthClass:[TencentOAuthclass]];

break;

default:

break;

}

}

onConfiguration:^(SSDKPlatformTypeplatformType,NSMutableDictionary*appInfo)

{

switch(platformType)

{

caseSSDKPlatformTypeWechat:

[appInfoSSDKSetupWeChatByAppId:@"XXXX"

appSecret:@"XXX"];

break;

//appid轉十六進制然后設置url

caseSSDKPlatformTypeQQ:

[appInfoSSDKSetupQQByAppId:@"XX"

appKey:@"XX"

authType:SSDKAuthTypeBoth];

break;

default:

break;

}

}];

}


- (void)setupJPush:(NSDictionary*)launchOptions

{

//推送

NSString*advertisingId = [[[ASIdentifierManagersharedManager]advertisingIdentifier]UUIDString];

if([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0) {

//可以添加自定義categories

[JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge|

UIUserNotificationTypeSound|

UIUserNotificationTypeAlert)

categories:nil];

}else{

//categories必須為nil

[JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|

UIRemoteNotificationTypeSound|

UIRemoteNotificationTypeAlert)

categories:nil];

}

//如不需要使用IDFA,advertisingIdentifier可為nil

[JPUSHServicesetupWithOption:launchOptionsappKey:appKey

channel:channel

apsForProduction:isProduction

advertisingIdentifier:advertisingId];

//消掉icon右上角badge通知數字

[UIApplicationsharedApplication].applicationIconBadgeNumber=0;

}

//這部分值得說一下,就是這里要獲取 服務器的時間 和自己手機的時間 去做一個差值的計算。 拿 服務器減本地時間獲得這個差值,然后有了這個差值以后,以后每次發送請求的時候,就拿這個差值去計算

//差值和本地時間相加

NSTimeIntervalretest =[zzDataManagerinstance].commonModel.cahzhiTime+ LocalTime;

然后把這個時間發給服務器,服務器去看這個時間的,如果這個時間相差太遠,就請求失效。

主要的目的是為了 防止用戶修改手機的時間,去做一些不好的操作!

- (void)reqSeverTime

{

[[APIClientsharedManager]netWorkGetSysTime:^(NSDictionary*response) {

NSTimeIntervalseverTime =[response[@"sysTime"]longValue];

//本地時間

NSTimeIntervalLocalTime = ((long)[[NSDatedate]timeIntervalSince1970] *1000);

//服務器時間減去本地時間

[zzDataManagerinstance].commonModel.cahzhiTime=severTime - LocalTime;

NSLog(@"responseTime:%@ commonModel.severTime %f",response,[zzDataManagerinstance].commonModel.severTime);

}failure:^(NSError*error) {

NSLog(@"error commonModel.severTime %@",error);

}];

}


- (void)setupWindowRootViewController

{

if([[NSUserDefaultsstandardUserDefaults]objectForKey:@"XXX"])

{

LYCTabBarController*lycTabbarController = [[LYCTabBarControlleralloc]init];

self.window.rootViewController= lycTabbarController;

}else{

//LYCLoginViewController *loginVC = [[LYCLoginViewController alloc] init];

LYCLoginViewController*loginVC = [[LYCLoginViewControlleralloc]init];

UINavigationController*loginNavVC = [[UINavigationControlleralloc]initWithRootViewController:loginVC];

self.window.rootViewController= loginNavVC;

}

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容