add message exercises

This commit is contained in:
lianxiang
2018-08-23 18:09:15 +08:00
parent 3b8f57d02f
commit d43d7eaaf6
51 changed files with 1713 additions and 122 deletions
+31
View File
@@ -13,6 +13,9 @@
#import "JPUSHService.h"
@interface AppDelegate ()
//保持后台长时间运行
@property (nonatomic,assign) UIBackgroundTaskIdentifier backgroundTask;
@property (nonatomic,strong) NSTimer *timer;
@end
@@ -46,9 +49,37 @@
// 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.
//后台模式
[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];