Ios 后台应用程序刷新
在我的应用程序中,我正在使用后台应用程序刷新。我已经检查了背景模式下的背景提取。当我点击Simulate background Fetch时,它在后台刷新数据。但若我的应用程序关闭,我从服务器更新数据,我的应用程序不会更新数据。甚至我都等了很长时间,大约一个小时,然后重新启动。请帮忙。 我的代码是:Ios 后台应用程序刷新,ios,objective-c,Ios,Objective C,在我的应用程序中,我正在使用后台应用程序刷新。我已经检查了背景模式下的背景提取。当我点击Simulate background Fetch时,它在后台刷新数据。但若我的应用程序关闭,我从服务器更新数据,我的应用程序不会更新数据。甚至我都等了很长时间,大约一个小时,然后重新启动。请帮忙。 我的代码是: -(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UI
-(void)application:(UIApplication *)application
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"Fetch Started");
[self getDataAtBAckground];
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"Fetch completed");
}
在didFinishLaunchingWithOptions中:
请在后台显示getDataAtBAckground。此外,请报告您的日志记录是否在应用程序暂停时发生。还请描述您的测试过程。你正在使用设备,是吗?你是独立于Xcode运行你的应用程序的,是吗?当你说如果我的应用程序关闭,你是指在后台还是通过双击home按钮并将应用程序从屏幕顶部刷下来强制关闭?如果您强制关闭应用程序,则不会进行后台刷新。@Beyers说得很好。@matt我正在独立于xcode的设备上进行测试。
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
return YES;
}
-(void)getDataAtBAckground {
//-------Get All Categories-------//
expense = [[Expense alloc]init];
[expense deleteAllCategories];
[expense deleteAllChannels];
NSString *str = [NSString stringWithFormat:@"http://myServerAddress/categories.php"];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if(error)
{
NSLog(@"%@",[error localizedDescription]);
}
else
{
NSArray *post = [json valueForKey:@"post"];
NSArray *categNameArray = [post valueForKey:@"name"];
NSArray *categImageArray = [post valueForKey:@"image"];
NSArray *categIdArray = [post valueForKey:@"id"];
for(int counter=0; counter<[categNameArray count]; counter++)
{
[expense addCategoryWithName:[categNameArray objectAtIndex:counter] image:[categImageArray objectAtIndex:counter] Catid:[categIdArray objectAtIndex:counter]];
}
}
}