地图二维码的扫描

首先 自动生成:
target ‘mapsaomiao’ do
pod ‘AMap3DMap’
pod ‘AMapSearch’
pod ‘AMapLocation’
pod ‘ZBarSDK’
end
地图二维码的扫描_第1张图片
开启权限:
Privacy - Location When In Use Usage Description 使用应用期间允许访问位置信息
Privacy - Location Usage Description 永不允许访问位置信息
Privacy - Location Always Usage Description 始终允许访问位置信息

然后在appdelegate.m里面写:
#import “AppDelegate.h”

#import
@interface AppDelegate ()

@end

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[AMapServices sharedServices] setEnableHTTPS:YES];
    [AMapServices sharedServices].apiKey = @“a5a335fcdb25ee5d71e94e78a9692e9b”;
    return YES;
    }

然后再在viewcontroller.m里面写:

#import “ViewController.h”
#import
#import
#import
#import “ZBarSDK.h”
#define ScreenFrame [[UIScreen mainScreen]bounds]
@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    ///地图需要v4.5.0及以上版本才必须要打开此选项(v4.5.0以下版本,需要手动配置info.plist)
    [AMapServices sharedServices].enableHTTPS = YES;

    ///初始化地图
    MAMapView *_mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];

    ///把地图添加至view
    [self.view addSubview:_mapView];

    ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
    _mapView.showsUserLocation = YES;
    _mapView.userTrackingMode = MAUserTrackingModeFollow;

    MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
    r.showsAccuracyRing = NO;///精度圈是否显示,默认YES
    r.showsHeadingIndicator = NO;///是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES
    r.fillColor = [UIColor redColor];///精度圈 填充颜色, 默认 kAccuracyCircleDefaultColor
    r.strokeColor = [UIColor blueColor];///精度圈 边线颜色, 默认 kAccuracyCircleDefaultColor
    r.lineWidth = 2;///精度圈 边线宽度,默认0
    r.enablePulseAnnimation = NO;///内部蓝色圆点是否使用律动效果, 默认YES
    r.locationDotBgColor = [UIColor greenColor];///定位点背景色,不设置默认白色
    r.locationDotFillColor = [UIColor grayColor];///定位点蓝色圆点颜色,不设置默认蓝色
    r.image = [UIImage imageNamed:@“你的图片”]; ///定位图标, 与蓝色原点互斥
    [_mapView updateUserLocationRepresentation:r];

    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 595, self.view.frame.size.width, self.view.frame.size.height-160)];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.cornerRadius=(self.view.frame.size.width)/2-10;
    view.layer.masksToBounds=YES;
    [self.view addSubview:view];

    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(155, 10, 100, 100)];
    [btn setImage:[UIImage imageNamed:@“2”] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    }

-(void)click{
ZBarReaderViewController * reader = [ZBarReaderViewController new];//初始化相机控制器
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;//基本适配
reader.showsHelpOnFail = YES;
reader.scanCrop = CGRectMake(0, 0, 1, 1);
ZBarImageScanner * scanner = reader.scanner;
[scanner setSymbology:25 config:0 to:0];

[self presentViewController:reader animated:YES completion:nil];

}

@end

你可能感兴趣的:(地图二维码的扫描)