小编wja*_*ans的帖子

如何在iOS应用程序中每n分钟更新一次后台位置?

我正在寻找一种在iOS应用程序中每n分钟更新一次后台位置的方法.我正在使用iOS 4.3,该解决方案适用于非越狱的iPhone.

我尝试/考虑了以下选项:

  • CLLocationManager startUpdatingLocation/startMonitoringSignificantLocationChanges:这根据预期在后台工作,基于配置的属性,但似乎不可能强制它每n分钟更新一次位置
  • NSTimer:当应用程序在前台运行但似乎不是为后台任务设计时,是否有效
  • 本地通知:本地通知可以每n分钟安排一次,但是无法执行某些代码来获取当前位置(用户无需通过通知启动应用程序).这种方法似乎也不是一种干净的方法,因为这不是应该使用的通知.
  • UIApplication:beginBackgroundTaskWithExpirationHandler:据我所知,当应用程序移动到后台而不是实现"长时间运行"的后台进程时,这应该用于在后台完成一些工作(也限制时间).

如何实施这些常规后台位置更新?

objective-c background-process core-location ios

202
推荐指数
9
解决办法
17万
查看次数

Spring引导不抱怨两个同名的bean

我有以下配置,其中有两个具有相同名称的Spring bean来自两个不同的配置类.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfiguration {

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
Run Code Online (Sandbox Code Playgroud)
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration 
public class OtherRestTemplateConfiguration {

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在注入(和使用)这样的bean:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class SomeComponent {

    @Autowired
    private RestTemplate restTemplate;

}
Run Code Online (Sandbox Code Playgroud)

现在,我的问题是:为什么Spring不抱怨有多个具有相同名称的bean?我希望在这里有一个例外,并且必须添加@Primary注释以确保正在使用正确的注释.

在旁注:即使我添加@Primary它仍然不总是注入正确的.

java spring spring-boot

10
推荐指数
1
解决办法
8605
查看次数

将ObjectMapper注入Spring Kafka serialiser/deserialiser

我正在使用Spring Kafka 1.1.2-RELEASE和Spring Boot 1.5.0 RC,我已经配置了一个自定义值serialiser/deserialiser类extend org.springframework.kafka.support.serializer.JsonSerializer/ org.springframework.kafka.support.serializer.JsonDeserializer.这些类确实使用了Jackson ObjectMapper,它可以通过构造函数提供.

是否有可能从我的Spring上下文中注入ObjectMapper?我已经配置了一个ObjectMapper,我想在serialiser/deserialiser中重用它.

java spring spring-boot spring-kafka

6
推荐指数
2
解决办法
2037
查看次数

位置管理员为旧位置提供新的时间戳

我在iPhone应用程序中遇到以下问题:

我定期启用位置管理器,我等待多个位置更新.收到新位置后,我会检查新位置的时间戳属性,以确定它是否是旧位置:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {

    numberOfUpdatesInInterval++;
    NSLog(@"%d;%f;%f;%.0f;%@;%@;%@",
                              numberOfUpdatesInInterval,
                              newLocation.coordinate.latitude,
                              newLocation.coordinate.longitude,
                              newLocation.horizontalAccuracy,
                              newLocation.timestamp,
                              [self getCurrentDateAsString],
                              newLocation);
}
Run Code Online (Sandbox Code Playgroud)

我现在遇到的问题是我收到了新的位置,其中时间戳是新的,但坐标仍然是我之前收到的旧位置.当我以120km/h的速度驾驶我的汽车时,我测试了这个,多次接收相同的坐标但是时间戳不同.我在iOS 4和5中遇到了同样的问题.

这怎么可能?或者我该如何处理这个问题?

cllocationmanager cllocation ios

5
推荐指数
1
解决办法
1424
查看次数