ARSession介绍

2018-04-06  本文已影响16人  流年易逝_李

ARSession是一个连接底层与AR视图之间的桥梁,其实ARSCNView内部所有的代理方法都是由ARSession来提供的

ARSession获取相机位置数据主要有两种方式

1)push。 实时不断的获取相机位置,由ARSession主动告知用户。通过实现ARSession的代理- (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame来获取

2)pull。 用户想要时,主动去获取。ARSession的属性currentFrame来获取

@interface ARSession : NSObject

/**代理*/

@property (nonatomic, weak) id delegate;

/**指定代理执行的线程

(主线程不会有延迟,子线程会有延迟),不指定的话默认主线程*/

@property (nonatomic, strong, nullable) dispatch_queue_t delegateQueue;

/**相机当前的位置(是由会话追踪配置计算出来的)

*/

@property (nonatomic, copy, nullable, readonly) ARFrame *currentFrame;

/**会话追踪配置*/

@property (nonatomic, copy, nullable, readonly) ARSessionConfiguration *configuration;

/**运行会话(这行代码就是开启AR的关键所在)*/

- (void)runWithConfiguration:(ARSessionConfiguration *)configuration NS_SWIFT_UNAVAILABLE("Use run(_:options:)");

- /**运行会话,只是多了一个参数ARSessionRunOptions:作用就是会话

ARSessionRunOptionResetTracking:表示重置追踪  ARSessionRunOptionRemoveExistingAnchors:移除现有锚点*/

- (void)runWithConfiguration:(ARSessionConfiguration *)configuration options:(ARSessi

onRunOptions)options NS_SWIFT_NAME(run(_:options:));

/**暂停会话*/

- (void)pause;

- (void)addAnchor:(ARAnchor *)anchor NS_SWIFT_NAME(add(anchor:));

- (void)removeAnchor:(ARAnchor *)an

chor NS_SWIFT_NAME(remove(anchor:));

@end

//session代理分类两部分,一个是观察者(KVO) 一个是委托者(代理)

#pragma mark - ARSessionObserver

//session KVO观察者

@protocol ARSessionObserver

@optional

/**session失败*/

- (void)session:(ARSession *)session didFailWithError:(NSError *)error;

/**相机改变追踪状态*/

- - (void)session:(ARSession *)session cameraDidChangeTrackingState:(ARCamera *)camera;

/**session意外断开

(如果开启ARSession之后,APP退到后台就有可能导致会话断开)*/

- (void)sessionWasInterrupted:(ARSession *)session;

/**session会话断开恢复(短时间退到后台再进入APP会自动恢复)*/

- (void)sessionInterruptionEnded:(ARSess

ion *)session;

@end

#pragma mark - ARSessionDelegate

@optional

/**相机当前状态(ARFrame:空间位置,图像帧等)更新*/

- (void)session:(ARSession *)session didUpdate

Frame:(ARFrame *)frame;

/**添加锚点*/

- (void)session:(ARSession *)session didAddAnchors:(NSArray*)anchors;

- (void)session:(ARSession *)session didUpdateAnchors:(NSArray*)

anchors;

/**移除锚点*/

- (void)session:(ARSession *)session didRemoveAnchors:(NSArray*)anchors;

- @end

上一篇 下一篇

猜你喜欢

热点阅读