我正在寻找一种在iOS应用程序中每n分钟更新一次后台位置的方法.我正在使用iOS 4.3,该解决方案适用于非越狱的iPhone.
我尝试/考虑了以下选项:
CLLocationManager startUpdatingLocation/startMonitoringSignificantLocationChanges:这根据预期在后台工作,基于配置的属性,但似乎不可能强制它每n分钟更新一次位置NSTimer:当应用程序在前台运行但似乎不是为后台任务设计时,是否有效UIApplication:beginBackgroundTaskWithExpirationHandler:据我所知,当应用程序移动到后台而不是实现"长时间运行"的后台进程时,这应该用于在后台完成一些工作(也限制时间).如何实施这些常规后台位置更新?
我有以下配置,其中有两个具有相同名称的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它仍然不总是注入正确的.
我正在使用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中重用它.
我在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中遇到了同样的问题.
这怎么可能?或者我该如何处理这个问题?