1. 二維碼
iOS7之前使用第三番 Z-Xing Z-Bar
iOS7之后系統(tǒng)提供原生方式
-
二維碼的生成,通過(guò)一定的規(guī)則把數(shù)據(jù)轉(zhuǎn)換成圖片
//1.創(chuàng)建一個(gè)種類的濾鏡
***二維碼
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
***條形碼
CIFilter *filter1 = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
//2.恢復(fù)濾鏡的默認(rèn)設(shè)置(清除已經(jīng)設(shè)置過(guò)的效果)
[filter setDefaults];
//3.將隱藏的地址變成二進(jìn)制數(shù)據(jù)
NSData *data = [@"http://www.baidu.com" dataUsingEncoding:NSUTF8StringEncoding];
//4.通過(guò)KVC的方式設(shè)置濾鏡,傳入要隱藏的data
//濾鏡就能夠依據(jù)data生成二維碼
[filter setValue:data forKey:@"inputMessage"];
//5.輸出二維碼圖片
CIImage *outputImage = [filter outputImage];
//6.將CIImage轉(zhuǎn)換成UIImage
UIImage *image = [UIImage imageWithCIImage:outputImage];
//7.顯示
self.imageView.image = image;
- 掃描二維碼
1. 打開(kāi)后置攝像頭
2. 從后置攝像頭中讀取數(shù)據(jù)輸入流
3. 把輸入流輸出到屏幕上---輸出流
4. 把輸入流和輸出流連接起來(lái)---管道session
5. 讓輸出流實(shí)時(shí)過(guò)濾數(shù)據(jù),監(jiān)聽(tīng)是否有二維碼(條形碼)如果有就通過(guò)協(xié)議通知我們
import "ViewController.h"
import <AVFoundation/AVFoundation.h>
@interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate>
- (IBAction)startScan:(id)sender;
/** 連接輸入輸出流的對(duì)象/
@property (nonatomic,strong)AVCaptureSession * session;
/* 用于展示輸出流的對(duì)象*/
@property (nonatomic,strong)AVCaptureVideoPreviewLayer * videoLayer;
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
}-
(IBAction)startScan:(id)sender {
//1.獲取后置攝像頭管理對(duì)象
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//2.獲取輸入流
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (error) {
NSLog(@"%@",error);
}
//3.創(chuàng)建輸出流 (把圖像顯示)
AVCaptureMetadataOutput *output = [AVCaptureMetadataOutput new];
//設(shè)置代理
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];//4.構(gòu)建連接通道
_session = [AVCaptureSession new];
[_session addInput:input];
[_session addOutput:output];//5.通道質(zhì)量設(shè)置(流暢 高清 標(biāo)清)
[_session setSessionPreset:AVCaptureSessionPresetHigh];//6.設(shè)置輸出流的類型(二維碼 條形碼...)一定要在通道連接之后設(shè)置,否則不起作用
output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode,AVMetadataObjectTypeCode128Code,AVMetadataObjectTypeEAN8Code,AVMetadataObjectTypeEAN13Code];//7.顯示
_videoLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
_videoLayer.frame = self.view.bounds;[self.view.layer addSublayer:_videoLayer];
//8.啟動(dòng)通道
[self.session startRunning];
}
pragma mark -AVCaptureMetadataOutputObjectsDelegate
//當(dāng)掃描到數(shù)據(jù)時(shí)
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
if (metadataObjects.count > 0) {
[_session stopRunning];
[_videoLayer removeFromSuperlayer];
//拿出掃描數(shù)據(jù)
AVMetadataMachineReadableCodeObject *object = metadataObjects.firstObject;
NSLog(@"掃描到的數(shù)據(jù)是:%@",[object stringValue]);
}
}```
2. 搖一搖
- 1 開(kāi)始搖一搖
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event - 2 結(jié)束搖一搖
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event - 3 取消搖一搖(被中斷,例如:來(lái)電)
-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
3. 社會(huì)化分享
- 4.1 分享到各方平臺(tái)误债。例如:分享到新浪微博->第三方登錄->分享
- 4.2 系統(tǒng)自帶的分享
->iOS6之后集成新浪微博
->iOS7之后支持騰訊微博
#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.創(chuàng)建類型
SLComposeViewController *cvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
//2.設(shè)置數(shù)據(jù)
[cvc setInitialText:@"潮濕的不得了"];
[cvc addImage:[UIImage imageNamed:@"icon"]];
//3.顯示
[self presentViewController:cvc animated:YES completion:nil];
//4.監(jiān)聽(tīng)
cvc.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
NSLog(@"發(fā)布成功");
}else{
NSLog(@"發(fā)布失敗");
}
};
}
@友盟分享
- 1 注冊(cè)并登陸
- 2 新建應(yīng)用獲得appkey
- 3 找到官方的Apple平臺(tái)集成文檔
如果運(yùn)行在真機(jī),程序崩潰 出現(xiàn)bitcode
Target -> Build Setting ->修改BitCode```
@[添加微信分享](http://dev.umeng.com/social/ios/detail-share#2_1)->設(shè)置scheme->設(shè)置白名單