测试设备:iPhone 5(iOS 7)
我有一个使用RegionMonitoring和的应用程序updateLocation.如果输入某个区域,didEnterRegion则按预期调用.然后我打电话startUpdatingLocation.但是该方法didUpdateToLocation仅被调用10-20次,而它应该更新位置直到计时器触发.
相关代码:
CLLocationManager *_locationManager;
NSTimer *_timer;
-(void)initLocationManager
{
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
[_locationManager setActivityType:CLActivityTypeOther];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[_locationManager setPausesLocationUpdatesAutomatically:NO];
[_locationManager setDistanceFilter:kCLDistanceFilterNone];
}
//Did Enter Region, called as expected:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[_locationManager startUpdatingLocation];
_timer = [NSTimer scheduledTimerWithTimeInterval:300.0f target:self selector:@selector(scheduleMethod:) userInfo:nil repeats:NO];
}
//Timer Fire Method:
- (void) scheduleMethod:(NSTimer*)timer
{
[Utils writeToLog:@"Timer-Stop"];
[_locationManager stopUpdatingLocation];
}
//This Method only called 10-20 Times (in …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个应用程序,它必须检查用户是否在后台输入他的家庭 wifi 网络。(像地理围栏,但只有在用户进入或退出他的家庭 wifi 时才运行代码......)
问题是,我没有找到一个干净的解决方案来做到这一点。有没有我失踪的通知?
在 Android 中,我刚刚对此进行了编程,并且我已经使用广播接收器完成了此操作,如果网络状态发生变化,AndroidOS 将进行广播。
iOS 中有没有类似的东西,我在 Apple Docs 中没有找到。
谢谢
编辑:iOS 7 是什么?现在有后台应用刷新服务。这有可能吗,还是仅用于下载?
什么是本地通知?
这有效:
struct list
{
int value;
struct list *next;
};
void addElement(struct list **l, int value)
{
if( *l == 0 )
{
*l = (struct list *) malloc(sizeof(struct list));
(*l)->value = value;
(*l)->next = 0;
}
else
{
struct list *new_element = (struct list *) malloc(sizeof(struct list));
new_element->value = value;
new_element->next = *l;
*l = new_element;
}
}
void printList(struct list *l)
{
struct list *temp;
for(temp = l;temp; temp = temp->next)
printf("%d ->", temp->value);
printf("%d",0);
}
int main(int …Run Code Online (Sandbox Code Playgroud)