Tag: 背景

iOS – backgroundTimeRemaining值没有显示预期的

我试图检查backgroundTimeRemaining的价值,但我得到了一个非常大的数字。 该属性的价值应该是对应的10分钟aprox,我已经在苹果的文档中看到 ,这样的价值是巨大的,当应用程序在前台。 但是,即使在后台,我也能获得很大的价值: – (void)applicationDidEnterBackground:(UIApplication *)application { bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ [application endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Background task NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining; NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / 60)); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining; NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / […]

重要的改变位置委托方法不被调用

我所有的代码都在AppDelegate.m中: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; _locationMgr = [[CLLocationManager alloc] init]; [_locationMgr setDelegate:self]; if([_locationMgr respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) [_locationMgr setAllowsBackgroundLocationUpdates:YES]; CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus]; if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) { NSLog(@"relaunching because of significant location change – restarting SLC"); [_locationMgr startMonitoringSignificantLocationChanges]; } else { if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) { NSLog(@"launching with authorization to […]

ASIHTTPRequest和背景

笏发生在我们开始一个请求,并在请求完成之前进入后台? 我们必须取消吗? 什么是正确的方式呢? PS:我不希望我的下载在用户进入后台时继续。 谢谢,

查看ApplicationWillResignActive中的控制器variables

我试图让我的计时器在后台运行,通过在进入背景时保存磁盘的时间,并在进入前台时检索它。 每个视图控制器都有一个定时器和一个由用户指定的timeInterval。 问题是,我不知道如何访问timeIntervalvariables。 我想我可以通过使用这样的东西来获得时间的差异(这会工作吗?): NSTimeInterval idleTime = [dateReturnedToForeground timeIntervalSinceDate:dateEnteredBackground]; NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:startDate]; elapsedTime -= idleTime; 每个视图控制器(和定时器/时间间隔)是这样访问的: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ DetailViewController *detailVC; if (![self.detailViewsDictionary.allKeys containsObject:indexPath]){ detailVC = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil]; [self.detailViewsDictionary setObject:detailVC forKey:indexPath]; detailVC.context = self.managedObjectContext; }else{ detailVC = self.detailViewsDictionary[indexPath]; } Tasks *task = [[self fetchedResultsController] objectAtIndexPath:indexPath]; detailVC.testTask = task; [[self navigationController] […]

主页button被按下时,CABasicAnimation消失

我正在实施一个游戏,其中我有一些CABasicAnimations。 例如,像这样: CABasicAnimation * borddroit = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; borddroit.fromValue = [NSNumber numberWithFloat:0.0f]; borddroit.toValue = [NSNumber numberWithFloat:749.0f]; borddroit.duration = t; borddroit.repeatCount = 1; [ImageSuivante2.layer addAnimation:borddroit forKey:@"borddroit"]; 我用这个函数暂停: -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; } 当我的应用程序进入后台,因为用户按下home键,animation正确设置暂停,但是当我重新打开我的应用程序,animation已经消失。 我怎么能修好它? 谢谢

NSTimer在后台的行为(addTimer:,beginBackgroundTaskWithExpirationHandler :)

Xcode 6.3.1 ARC已启用,适用于iOS 8.3 我需要帮助了解一个奇怪的行为,当我尝试在应用程序进入后台后维护一个单例共享计时器的时候遇到了一个奇怪的行为。 以前我不关心这个NSTimer,因为它使用后台位置服务在后台更新用户位置。 但是,我想解决的情况是用户在后台或位置更新时拒绝位置更新。 位置和计时器为我的应用程序携手共进。 我在下面的主题和网站post中通过了相当多的信息。 苹果公司的后台执行 iOS 7 Background App Refresh Tutorial http://www.infragistics.com/community/blogs/stevez/archive/2013/01/24/ios-tips-and-tricks-working-in-the-background.aspx 如何让我的应用程序在后台运行NSTimer? 如何在后台线程上创buildNSTimer? 计划NSTimer当应用程序在后台? Background Modes Tutorial: Getting Started iPhone – 背景调查事件 在这些信息之外,我能够推导出(2)使计时器运行约8小时,而没有iOS在180秒之后终止应用程序的方法。 (3分钟)的执行时间,苹果公司的文件承诺。 这里是代码: AppDelegate.h (方法#1或#2未更改) #import <UIKit/UIKit.h> @interface MFAppDelegate : UIResponder <UIApplicationDelegate> { UIBackgroundTaskIdentifier bgTask; NSInteger backgroundTimerCurrentValue; } @property (retain, nonatomic) NSTimer *someTimer; @end AppDelegate.m (方法#1) <… […]

UIAlertView更改背景颜色

您好我想要更改UiAlertview BG颜色为绿色,使用setBGcolor它给我下面的输出,其中有一个深色的SetBGColor指定,另一种方式来删除背景颜色或别的东西。

定期更新位置背景Swift 3.0 iOS 10

我做一个应用程序,当它进入后台我需要发送到服务器一些周期性的数据。 为了从后台唤醒,我使用后台更新的重要位置(较低的电池)。 我注意到,当从wifi / 3g手机细胞或3G时改变手机塔的位置更新,但我的问题是,如果用户不移动(然后手机塔不改变)的位置不更新和应用程序doest醒来,然后我不能发送数据到服务器。 你知道一些方法来解决这个问题吗? 我在AppDelegate文件中执行所有这些操作: class AppDelegate: UIResponder, UIApplicationDelegate , CLLocationManagerDelegate{ var manager = CLLocationManager() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { manager.desiredAccuracy = kCLLocationAccuracyBest manager.delegate = self manager.requestAlwaysAuthorization() manager.allowsBackgroundLocationUpdates = true return true } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ sendDataToServer() } func applicationDidEnterBackground(_ application: UIApplication) { […]

我可以让我的WatchKit应用程序在Apple Watch的后台运行吗?

我想知道是否有我的WatchKit应用程序在后台运行,或者如果我可以编程启动(即从非活动状态转移到活动状态)一旦满足某些条件? 当WK应用程序处于打开状态并处于活动状态时,我的应用程序运行良好,当iPhone处于睡眠状态,或者父应用程序处于BG模式时,它甚至可以正常运行。 但是,我真的需要我的应用程序继续在手表本身的背景下运行。 这可能吗?

本地通知不在设备上工作,但在模拟器上工作

我读过一些如何使用UILocalNotification的指南。 所以我从第一次尝试就试过了,没有成功。 要在AppDelegate.m中注册通知,我使用: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { … //if it is iOS 8 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil]; [application registerUserNotificationSettings:settings]; } else // if iOS 7 { UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [application registerForRemoteNotificationTypes:myTypes]; } UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (locationNotification) { // Set […]