可以在iAd中使用iPhone相机吗?

时间:2012-05-15 22:01:45

标签: ios iad

是否可以在iAd中访问相机?

我读到创建iAds的语言是JS所以我相信它无法访问。但关于iAd的文档并不多。

1 个答案:

答案 0 :(得分:1)

是的,有办法做到这一点。我建议你下载iAd Producer。安装后,.dmg磁盘中有一个“额外”目录。有一些有用的例子,其中之一是相机的访问和图像处理。

https://developer.apple.com/iad/iadproducer/

在任何情况下,这是一个按钮的小片段,它会触发相机并在图像视图中显示拍摄的照片:

var button = this.viewController.outlets.button;

var image = this.viewController.outlets.image;

this.onViewTouchUpInside = function(event){

// 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);

};

if(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);

}

祝你好运!