高新技术:二维码 & 摇一摇 & 分享

2016-03-20  本文已影响0人  WhisperMax

1. 二维码

iOS7之前使用第三番 Z-Xing Z-Bar
iOS7之后系统提供原生方式

***二维码
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
***条形码
CIFilter *filter1 = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
//2.恢复滤镜的默认设置(清除已经设置过的效果)
[filter setDefaults];

//3.将隐藏的地址变成二进制数据
NSData *data = [@"http://www.baidu.com" dataUsingEncoding:NSUTF8StringEncoding];

//4.通过KVC的方式设置滤镜,传入要隐藏的data
//滤镜就能够依据data生成二维码
[filter setValue:data forKey:@"inputMessage"];

//5.输出二维码图片
CIImage *outputImage = [filter outputImage];

//6.将CIImage转换成UIImage
UIImage *image = [UIImage imageWithCIImage:outputImage];

//7.显示
self.imageView.image = image;
- 扫描二维码
 1. 打开后置摄像头
 2. 从后置摄像头中读取数据输入流
 3. 把输入流输出到屏幕上---输出流
 4. 把输入流和输出流连接起来---管道session
 5. 让输出流实时过滤数据,监听是否有二维码(条形码)如果有就通过协议通知我们

import "ViewController.h"

import <AVFoundation/AVFoundation.h>

@interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate>

@implementation ViewController

pragma mark -AVCaptureMetadataOutputObjectsDelegate

//当扫描到数据时
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
if (metadataObjects.count > 0) {
[_session stopRunning];
[_videoLayer removeFromSuperlayer];
//拿出扫描数据
AVMetadataMachineReadableCodeObject *object = metadataObjects.firstObject;
NSLog(@"扫描到的数据是:%@",[object stringValue]);
}
}```

2. 摇一摇

3. 社会化分享

#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()

@end

@implementation ViewController

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
        NSLog(@"不支持新浪微博");
    }
    //1.创建类型
    SLComposeViewController *cvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
    //2.设置数据
    [cvc setInitialText:@"潮湿的不得了"];
    [cvc addImage:[UIImage imageNamed:@"icon"]];
    //3.显示
    [self presentViewController:cvc animated:YES completion:nil];
    //4.监听
    cvc.completionHandler = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultDone) {
            NSLog(@"发布成功");
        }else{
            NSLog(@"发布失败");
        }
    };
}

@友盟分享

如果运行在真机,程序崩溃 出现bitcode
 Target -> Build Setting ->修改BitCode```
@[添加微信分享](http://dev.umeng.com/social/ios/detail-share#2_1)->设置scheme->设置白名单
上一篇下一篇

猜你喜欢

热点阅读