小编ja.*_*ja.的帖子

CLLocationManager startUpdatingLocation不调用locationManager:didUpdateLocations:或locationManager:didFailWithError:

我正在尝试使用CLLocationManager我的iOS项目中的框架来访问用户的位置,但是当我打电话时

[locationManager startUpdatingLocation]
Run Code Online (Sandbox Code Playgroud)

既不locationManager:didUpdateLocations:locationManager:didFailWithError:越来越调用.

//myViewController.h
@interface myViewController : UITableViewController <CLLocationManagerDelegate>
@end

//myViewController.m
@implementation myViewController{
    CLLocationManager *locationManager;
}

//edit
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
}
//finish edit

-(void)getLocation
{
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc]
                           initWithTitle:@"Error" 
                                 message:@"Failed to Get Your Location"              
                                delegate:nil 
                       cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil];
[errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *newLocation = …
Run Code Online (Sandbox Code Playgroud)

objective-c cllocationmanager ios

37
推荐指数
4
解决办法
4万
查看次数

具有完成块的Objective-C方法返回我想在完成块中使用的值

我曾经多次使用AFNetworking为iOS编码遇到过这个问题,但直到现在我才找到了解决方法.

基本上,我想进行一个API调用,它将一个值返回给我想要在调用的完成块中使用的主线程.

更具体地说,我在我的数据库中创建了初始"推文" 之后,我有一个帖子对象(比如发布推文或其他内容),它与我想要POST的#tags和@tags相关联.我需要它在方法的完成块中,因为我需要使用post_id作为发布#tags和@tags的参数:

-(void)postToDB
{
    _postId = [[[ReelRailsAFNClient sharedClient] createPostWithParameters:
                                                            @{@"user_id":_userId,
                                                              @"caption":_caption}
                                            CompletionBlock:^(NSError *error) {
                                                if(!error){
                                                    [self postHashtagsToDB:_postId];
                                                    [self postAttagsToDB:_postId];
                                                 }
                                            }] postId];
    }
Run Code Online (Sandbox Code Playgroud)

在postHashtagsToDB和postAttagsToDB的主体内部,_postId的计算结果为(null).如何捕捉和注入到帖子ID postHashtagsToDBpostATtagsToDB

谢谢,

JA

编辑:

这是我对createPostWithParameters的方法定义:CompletionBLock:

- (Post*) createPostWithParameters:(NSDictionary*)parameters
              CompletionBlock:(AFNClientErrorCompletionBlock)block{
    Post *post = [[Post alloc] init];

    [self POST:@"posts" parameters:parameters
         success:^(NSURLSessionDataTask *task, id responseObject){
            NSLog(@"Post Created Successfully");
            post = responseObject;
            block(nil);
     }failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"Post Not Created");
            block(error);
     }];
    return post;
}
Run Code Online (Sandbox Code Playgroud)

multithreading ios objective-c-blocks afnetworking-2

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