126 lines
4.7 KiB
Objective-C
126 lines
4.7 KiB
Objective-C
//
|
||
// AppDelegate.m
|
||
// GIGA
|
||
//
|
||
// Created by lianxiang on 2018/8/13.
|
||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||
//
|
||
|
||
#import "AppDelegate.h"
|
||
#import "AppDelegate+GiGaConfig.h"
|
||
#import "AppDelegate+ThirdParty.h"
|
||
#import "GiGaUserDefault.h"
|
||
#import "JPUSHService.h"
|
||
#import "GiGaLocalNotificationManager.h"
|
||
|
||
@interface AppDelegate ()
|
||
//保持后台长时间运行
|
||
@property (nonatomic,assign) UIBackgroundTaskIdentifier backgroundTask;
|
||
@property (nonatomic,strong) NSTimer *timer;
|
||
|
||
@end
|
||
|
||
@implementation AppDelegate
|
||
|
||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||
// Override point for customization after application launch.
|
||
//[NSThread sleepForTimeInterval:1];//延迟启动
|
||
|
||
_isMasking = NO;
|
||
|
||
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
|
||
[self registLocalNotification];
|
||
|
||
[self configThridPartyWithOptions:launchOptions];
|
||
|
||
[self configEnvironment];
|
||
|
||
[self setupRootVC];
|
||
//广告页
|
||
[self creatAdView];
|
||
//[self setupTabBarController];
|
||
|
||
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.
|
||
|
||
|
||
// 当 开启面膜时间 长期保持后台模式
|
||
if (_isMasking) {
|
||
[self creatBackGoundTask];
|
||
}
|
||
//[self creatBackGoundTask];
|
||
|
||
}
|
||
|
||
-(void)creatBackGoundTask{
|
||
//告诉系统当前app在后台有任务处理,需要时间
|
||
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
||
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
|
||
self.backgroundTask = UIBackgroundTaskInvalid;
|
||
|
||
}];
|
||
self.timer = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(applyToActiveForMoreTime) userInfo:nil repeats:YES];
|
||
[self.timer fire];
|
||
}
|
||
|
||
-(void)applyToActiveForMoreTime{
|
||
|
||
//如果系统给的剩余时间小于60秒 就终止当前的后台任务,再重新初始化一个后台任务,重新让系统分配时间,这样一直循环下去,保持APP在后台一直处于active状态。
|
||
if ([UIApplication sharedApplication].backgroundTimeRemaining < 60.0) {
|
||
{//如果剩余时间小于60秒
|
||
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
|
||
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
||
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
|
||
self.backgroundTask = UIBackgroundTaskInvalid;
|
||
}];
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||
application.applicationIconBadgeNumber = 0;
|
||
[JPUSHService resetBadge];
|
||
|
||
// 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.
|
||
}
|
||
|
||
- (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:.
|
||
|
||
//app 挂起 面膜时间未结束 将发送本地通知提醒
|
||
|
||
if (_isMasking) {
|
||
|
||
[[GiGaLocalNotificationManager localNotifiationCenter] sendLocalNotification:@"闹钟提醒!" fireTimeInterval:2 alertAction:@"面膜时间已添加闹钟提醒!" withIdentifier:kLOCALNotifiID_APPTERMINAL];
|
||
}
|
||
|
||
}
|
||
|
||
-(void)remoteControlReceivedWithEvent:(UIEvent *)event
|
||
{
|
||
if (event.type == UIEventTypeRemoteControl ) {
|
||
|
||
|
||
}
|
||
}
|
||
|
||
@end
|