小编Max*_*980的帖子

- [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]错误

这是我的代码,显示地图上当前位置的警报和蓝点:

MapName.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>


@interface MapName : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>

@property (strong, nonatomic) IBOutlet MKMapView *MapName;
@property (strong, nonatomic) CLLocationManager *locationManager;

@end
Run Code Online (Sandbox Code Playgroud)

MapName.m

- (void)viewDidLoad
{
[super viewDidLoad];

self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];

//Center the map
[self gotoLocation];

//Show current position
_MapName.showsUserLocation = YES;

}
Run Code Online (Sandbox Code Playgroud)

我已将密钥NSLocationWhenIsUseUsageDescription作为字符串添加到Info.plist中.我在Xcode上仍然遇到同样的错误.

iphone core-location mapkit xcode6 ios8

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

隐式转换失去整数精度:'unsigned long' 到 'int' - 错误

我在这里看到了一些关于相同错误的问答,但没有一个有帮助。我仍然遇到同样的错误。我需要改变什么?这就是我现在所拥有的。
错误与这一行有关: imageIndex = (imageIndex < 0) ? ([图像数] -1):
感谢您的帮助!

#import "Photogallery.h"

@interface Photogallery ()


@end

@implementation Photogallery
@synthesize imageView;
int imageIndex = 10;

- (void)viewDidLoad {
[super viewDidLoad];


}
- (IBAction)handleSwipe:(UIGestureRecognizer *)sender {

NSArray *images=[[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9.jpg",@"10.jpg", nil];

UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *)sender direction];

switch (direction) {
    case UISwipeGestureRecognizerDirectionLeft:
        imageIndex++;
        break;
    case UISwipeGestureRecognizerDirectionRight:
        imageIndex--;
        break;

    default:
        break;
}
imageIndex = (imageIndex < 0) ? ([images count] -1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}


@end
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c uikit ios

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

标签 统计

cocoa-touch ×1

core-location ×1

ios ×1

ios8 ×1

iphone ×1

mapkit ×1

objective-c ×1

uikit ×1

xcode6 ×1