108 lines
3.7 KiB
Objective-C
108 lines
3.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 {
|
|
|
|
}
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
|
|
// 当 开启面膜时间 app长期保持后台模式
|
|
if (_isMasking) {
|
|
[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];
|
|
}
|
|
|
|
- (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
|