Tag: 客体

iOS背景获取时间限制崩溃

我已经设置了背景获取,使用NSScreencast第92集的轮廓。 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { … [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; … } – (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if ([[MyAppAPIClient manager] reachable] && [[Session manager] userSignedIn]) { [[[Session manager] user] fetchBackgroundWithSuccess:^(NSURLSessionDataTask *task, NSDictionary *responseObject) { completionHandler(UIBackgroundFetchResultNewData); } failure:^(NSURLSessionDataTask *task, NSError *error) { completionHandler(UIBackgroundFetchResultFailed); }]; } else completionHandler(UIBackgroundFetchResultNoData); } 对于fetchBackgroundWithSuccess:failure方法,我正在使用AFNetworking NSURLSessionDataTask 。 不幸的是,有时我得到错误 MyApp[3344] has active […]

AFNetworking版本2内容types错误

我试图做一个iphone应用程序,将与特定的JIRA服务器进行交互。 我有以下代码login: NSURL *url = [[NSURL alloc] initWithString:@"https://mycompany.atlassian.net/rest/auth/latest/session/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *postString = [NSString stringWithFormat:@"{\"username\":\"%@\",\"password\":\"%@\"}", username, password]; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept" ]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { […]

replaceAFNetworking 2.x中的AFJSONRequestOperation

我正在做一个基本的iPhone应用程序与HTML请求,按照本教程。 本教程让我在AFNetworking中使用AFJSONRequestOperation。 麻烦的是,我正在使用AFNetworking版本2,它不再有AFJSONRequestOperation。 所以,当然,这个代码(从教程中的“ 查询iTunes StoresearchAPI ”标题下的大约一半)不能编译: NSURL *url = [[NSURL alloc] initWithString: @"http://itunes.apple.com/search?term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"%@", JSON); } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; […]