是否可以访问 iAd 中的摄像头?
我读到创建 iAds 的语言是 JS,所以我相信它不能被访问。但是关于 iAd 的文档并不多。
是的,有办法做到这一点。我建议你下载 iAd Producer。安装后,.dmg 磁盘中有一个“额外”目录。有一些有用的例子,其中之一是相机的访问和图像处理。
https://developer.apple.com/iad/iadproducer/
无论如何,这是一个按钮的小片段,它将触发相机并在图像视图中显示拍摄的照片:
var button = this.viewController.outlets.button;
var image = this.viewController.outlets.image;
this.onViewTouchUpInside = 函数(事件){
// Access the camera object
var camera = window.ad.camera;
// if the API is unavailable, the object will be null
if (!camera) {
if (iAd.Device.iOSVersionLessThan('5.0')) {
alert('The Camera API is not available in iOS ' + iAd.Device.iOS_VERSION);
}
else {
alert('The Camera API could not be accessed.');
}
return;
}
// Reason from the app to explain the user
var reason = 'The app would like to take a photo';
camera.present(reason);
};
如果(window.ADCamera){
this.viewController.addEventListener(ADCamera.ADCameraUserTookPicture, function (event) {
// access the camera object
var camera = window.ad.camera;
// access the new picture
var newPicture = camera.currentPictureURI;
// set the image view's image to the new picture
image.image = new iAd.Image(newPicture);
}, false);
this.viewController.addEventListener(ADCamera.ADCameraUserCanceledPicture, function (event) {
}, false);
}
祝你好运!