本文按三部分來(lái)寫(xiě),
第一部分總結(jié)下該項(xiàng)目用到的關(guān)于 appdelegate ?的 方法和涉及的一些功能。
第二部分主要是用于介紹下,沒(méi)有涉及的方法和功能。
第三部分,擴(kuò)展一下,用到的和沒(méi)用到的功能一個(gè)部分補(bǔ)充。
第一部分:
先看一下總共用到了appdelegate里的哪些方法
1.程序載入后
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
//設(shè)置狀態(tài)欄顏色UIStatusBarStyleDefault = 0黑色文字,淺色背景時(shí)使UIStatusBarStyleLightContent = 1白色文字,深色背景時(shí)使用
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];
//設(shè)置配置IQKeyboard管理者
[selfsetupIQKeyboardManager];
//設(shè)置配置分享軟件開(kāi)發(fā)包Software Development Kit
[selfsetupShareSDK];
//設(shè)置jpush推送
[selfsetupJPush:launchOptions];
//請(qǐng)求服務(wù)器時(shí)間,和本地進(jìn)行矯正
[selfreqSeverTime];
//設(shè)置根視圖
[selfsetupWindowRootViewController];
//設(shè)置崩潰日志記錄bugly software dvelopment kit.
[BuglystartWithAppId:@"XXXXXXX"];
returnYES;
}
2.applicationDidBecomeActive 應(yīng)用程序掛起、復(fù)原與終止.? 英語(yǔ)字面意思是應(yīng)用程序變得活躍時(shí), 這個(gè)方法,主要是為了需求,給服務(wù)器一次記錄,每次都請(qǐng)求一次接口
- (void)applicationDidBecomeActive:(UIApplication*)application {
[[APIClientsharedManager]netReqNotify:^(NSDictionary*responseDic) {
NSLog(@"激活喚醒:%@",responseDic);
}failure:^(NSError*error) {
NSLog(@"激活喚醒:error %@",error);
}];
}
}
3.關(guān)于通知,推送 ?
//Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
/ /告訴委托應(yīng)用成功注冊(cè)蘋(píng)果推送通知服務(wù)(apn)。
- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
/// Required -注冊(cè)DeviceToken
[JPUSHServiceregisterDeviceToken:deviceToken];
}
//Called when your app has received a remote notification.
/ /時(shí)調(diào)用應(yīng)用程序遠(yuǎn)程通知已收到。
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHServicehandleRemoteNotification:userInfo];
}
接收遠(yuǎn)程通知
- (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.關(guān)于finish 里的 setup 方法
這個(gè)管理文本框鍵盤(pán) 第三方代碼,很不錯(cuò),我這里的版本有點(diǎn)舊
- (void)setupIQKeyboardManager
{
IQKeyboardManager*manager = [IQKeyboardManagersharedManager];
manager.enable=YES;
manager.shouldResignOnTouchOutside=YES;
manager.shouldToolbarUsesTextFieldTintColor=YES;
manager.enableAutoToolbar=NO;
manager.toolbarManageBehaviour=IQAutoToolbarBySubviews;
}
這里的22 23 24 是分享平臺(tái)的縮寫(xiě),具體看文檔。
- (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轉(zhuǎn)十六進(jìn)制然后設(shè)置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通知數(shù)字
[UIApplicationsharedApplication].applicationIconBadgeNumber=0;
}
//這部分值得說(shuō)一下,就是這里要獲取 服務(wù)器的時(shí)間 和自己手機(jī)的時(shí)間 去做一個(gè)差值的計(jì)算。 拿 服務(wù)器減本地時(shí)間獲得這個(gè)差值,然后有了這個(gè)差值以后,以后每次發(fā)送請(qǐng)求的時(shí)候,就拿這個(gè)差值去計(jì)算
//差值和本地時(shí)間相加
NSTimeIntervalretest =[zzDataManagerinstance].commonModel.cahzhiTime+ LocalTime;
然后把這個(gè)時(shí)間發(fā)給服務(wù)器,服務(wù)器去看這個(gè)時(shí)間的,如果這個(gè)時(shí)間相差太遠(yuǎn),就請(qǐng)求失效。
主要的目的是為了 防止用戶(hù)修改手機(jī)的時(shí)間,去做一些不好的操作!
- (void)reqSeverTime
{
[[APIClientsharedManager]netWorkGetSysTime:^(NSDictionary*response) {
NSTimeIntervalseverTime =[response[@"sysTime"]longValue];
//本地時(shí)間
NSTimeIntervalLocalTime = ((long)[[NSDatedate]timeIntervalSince1970] *1000);
//服務(wù)器時(shí)間減去本地時(shí)間
[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;
}
}