Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';使用CDVPlugin从phonegap 2.7.0中的javascript访问本机iOS?_Javascript_Ios_Objective C_Cordova - Fatal编程技术网

我能';使用CDVPlugin从phonegap 2.7.0中的javascript访问本机iOS?

我能';使用CDVPlugin从phonegap 2.7.0中的javascript访问本机iOS?,javascript,ios,objective-c,cordova,Javascript,Ios,Objective C,Cordova,我正在为iOS 6使用xcode 4.5.2开发phonegap 2.7.0 web应用程序。在我的web应用程序中,包含持续时间为6秒的视频录制选项。所以我从“”开始做这个过程 现在我正试图通过使用CDVPlugin将本机iOS与Phonegap混合。因为我在homescreen.html中有一个图像(照相机图标),当我单击该图像时,图像标记onclick()会触发并调用PBJViewController.m文件中的-(void)_setup()方法。因此mainscreen.html是隐藏和

我正在为iOS 6使用xcode 4.5.2开发phonegap 2.7.0 web应用程序。在我的web应用程序中,包含持续时间为6秒的视频录制选项。所以我从“”开始做这个过程

现在我正试图通过使用CDVPlugin将本机iOS与Phonegap混合。因为我在homescreen.html中有一个图像(照相机图标),当我单击该图像时,图像标记onclick()会触发并调用PBJViewController.m文件中的-(void)_setup()方法。因此mainscreen.html是隐藏和显示带有一些自定义设计的相机选项

因此,我将PBJViewController.h&PBJViewController.m、PBJStrobeView.h&PBJStrobeView.m、pbjvisionuities.h&pbjvisionuities.m和最后一个PBJVision.h&PBJVison.m文件放在plugins文件夹中

然后我创建一个名为PBJViewController.js的JavaScript文件,并将其添加到www文件夹中

PBJViewController.js

function PBJViewController()
{

}


loadingalert.prototype._setup = function()
{
    //this.resultCallback(res);
    cordova.exec("PBJViewController._setup");
}


cordova.addConstructor(function() {

                       if(!window.plugins)
                       {
                       window.plugins = {};
                       }
                       //window.plugins.loadingalert = new PBJViewController();
                       window.loadingalert = new PBJViewController();
                       });
然后我在homescreen.html文件的函数video()中编写了调用代码

homescreen.html

  function video()
  {
       alert("video function");

      $('#loader').hide();
      $('#divcontroller').hide();
      $('#menuid').hide();
      $('#home_feeds').hide();

      loadingalert._setup();
      //window.plugins.loadingalert._setup();



      //objloading._setup();
      //window.location = "js-call:myObjectiveCFunction";
  //window.location.href='video.html?user_id='+userid+'&fb_token='+getValue("fb_token");
  }
我在PBJViewController.h文件中做了一些更改

PBJViewController.h

   #import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>

@interface PBJViewController : CDVPlugin <UIWebViewDelegate>
{
     IBOutlet UIWebView *webView;

}

-(void)_setup:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options;

@end
#导入
#进口
@接口PBJViewController:CDVPlugin
{
ibuiwebview*webView;
}
-(void)_setup:(NSMutableArray*)paramArray with dict:(NSMutableDictionary*)选项;
@结束
并在PBJViewcontroller.m文件中

    #import "PBJViewController.h"
#import "PBJVision.h"
#import "PBJStrobeView.h"
#import <Cordova/CDVPlugin.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <MediaPlayer/MediaPlayer.h>

@interface UIButton (ExtendedHit)

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;

@end

@implementation UIButton (ExtendedHit)

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    CGRect relativeFrame = self.bounds;
    UIEdgeInsets hitTestEdgeInsets = UIEdgeInsetsMake(-35, -35, -35, -35);
    CGRect hitFrame = UIEdgeInsetsInsetRect(relativeFrame, hitTestEdgeInsets);
    return CGRectContainsPoint(hitFrame, point);
}

@end

@interface PBJViewController () <
    UIGestureRecognizerDelegate,
    PBJVisionDelegate,
    UIAlertViewDelegate>
{
    UIView *view;
    PBJStrobeView *_strobeView;
    UIButton *_doneButton;
    UIButton *_flipButton;

    UIView *_previewView;
    AVCaptureVideoPreviewLayer *_previewLayer;
    MPMoviePlayerViewController *playerController;
    MPMoviePlayerController *moviePlayer;
    UILabel *_instructionLabel;
    UILabel *ticker;
    NSTimer *timer;
    //NSDate *startDate;
    NSTimeInterval startDate;
    int hours, minutes, seconds;
    int secondsLeft;
    int counter;
    int timeRemaining;
    int i;
    NSTimeInterval elapsedTime;


    UILongPressGestureRecognizer *_longPressGestureRecognizer;
    BOOL _recording;
    BOOL running;

    ALAssetsLibrary *_assetLibrary;
    __block NSDictionary *_currentVideo;


    //NSTimeInterval coding..

    int currMinute;
    int currSecond;
    int currHour;
    int mins;
    NSTimeInterval secondsAlreadyRun;
    NSTimeInterval startTime;
    NSDate *startDate1;


}
//@property (nonatomic, retain) IBOutlet UIView *containerView;
@property (strong, nonatomic) MPMoviePlayerController *moviePlayerController;
@property (nonatomic, strong) NSString *videoPath;

@end

@implementation PBJViewController

//@synthesize containerView;
@synthesize moviePlayerController;
@synthesize videoPath;

#pragma mark - init


/*- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    //counter = 0;
    //ticker.text = [NSString stringWithFormat:@"%d", counter];

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _assetLibrary = [[ALAssetsLibrary alloc] init];
        //[self _setup];
    }
    return self;
}*/

- (CDVPlugin *)initWithWebView:(UIWebView *)theWebView
{
    self = (PBJViewController *)[super initWithWebView:theWebView];

    if (self) {
        _assetLibrary = [[ALAssetsLibrary alloc] init];
    }

    return self;
}


/*-(void) viewDidLoad
{
    webView = [[UIWebView alloc] init];
    // Register the UIWebViewDelegate in order to shouldStartLoadWithRequest to be called (next function)
    webView.delegate = self;

}*/


- (void)dealloc
{
    [UIApplication sharedApplication].idleTimerDisabled = NO;
    _longPressGestureRecognizer.delegate = nil;

    [super dealloc];
}

//- (void)_setup
-(void)_setup:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options;
{
    NSLog(@"Yes inheriting from homescreen btn click");
    running = false;
    secondsLeft = 67;
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
    view.backgroundColor = [UIColor blackColor];
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    CGFloat viewWidth = CGRectGetWidth(view.frame);

    // done button
    _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _doneButton.frame = CGRectMake(viewWidth - 20.0f - 20.0f, 20.0f, 20.0f, 20.0f);

    UIImage *buttonImage = [UIImage imageNamed:@"capture_yep"];
    [_doneButton setImage:buttonImage forState:UIControlStateNormal];

    [_doneButton addTarget:self action:@selector(_handleDoneButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_doneButton];

    // elapsed time and red dot
    _strobeView = [[PBJStrobeView alloc] initWithFrame:CGRectZero];
    CGRect strobeFrame = _strobeView.frame;
    strobeFrame.origin = CGPointMake(15.0f, 15.0f);
    _strobeView.frame = strobeFrame;
    [view addSubview:_strobeView];

    // preview
    _previewView = [[UIView alloc] initWithFrame:CGRectZero];
    _previewView.backgroundColor = [UIColor blackColor];
    CGRect previewFrame = CGRectZero;
    previewFrame.origin = CGPointMake(0, 60.0f);
    CGFloat previewWidth = view.frame.size.width;
    previewFrame.size = CGSizeMake(previewWidth, previewWidth);
    _previewView.frame = previewFrame;

    // add AV layer
    _previewLayer = [[PBJVision sharedInstance] previewLayer];
    CGRect previewBounds = _previewView.layer.bounds;
    _previewLayer.bounds = previewBounds;
    _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    _previewLayer.position = CGPointMake(CGRectGetMidX(previewBounds), CGRectGetMidY(previewBounds));
    [_previewView.layer addSublayer:_previewLayer];
    [view addSubview:_previewView];

    // instruction label
    _instructionLabel = [[UILabel alloc] initWithFrame:view.bounds];
    _instructionLabel.textAlignment = NSTextAlignmentCenter;
    _instructionLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15.0f];
    _instructionLabel.textColor = [UIColor whiteColor];
    _instructionLabel.backgroundColor = [UIColor blackColor];
    _instructionLabel.text = NSLocalizedString(@"Touch and hold to record", @"Instruction message for capturing video.");
    [_instructionLabel sizeToFit];
    CGPoint labelCenter = _previewView.center;
    labelCenter.y += ((CGRectGetHeight(_previewView.frame) * 0.5f) + 35.0f);
    _instructionLabel.center = labelCenter;
    [view addSubview:_instructionLabel];

    ticker = [[UILabel alloc] initWithFrame:CGRectMake(230, 100, 80, 20)];
    ticker.textAlignment = NSTextAlignmentLeft;
    ticker.font = [UIFont fontWithName:@"HelveticaNeue" size:15.0f];
    ticker.textColor = [UIColor whiteColor];
    ticker.backgroundColor = [UIColor blackColor];
    ticker.text = @"00:00:00";
    [_previewView addSubview:ticker];


    // press to record gesture
    _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
    _longPressGestureRecognizer.delegate = self;
    _longPressGestureRecognizer.minimumPressDuration = 0.0f;
    _longPressGestureRecognizer.allowableMovement = 10.0f;
    [_longPressGestureRecognizer addTarget:self action:@selector(_handleLongPressGestureRecognizer:)];

    // gesture view to record
    UIView *gestureView = [[UIView alloc] initWithFrame:CGRectZero];
    CGRect gestureFrame = view.bounds;
    gestureFrame.origin = CGPointMake(0, 60.0f);
    gestureFrame.size.height -= 10.0f;
    gestureView.frame = gestureFrame;
    [view addSubview:gestureView];
    [gestureView addGestureRecognizer:_longPressGestureRecognizer];

    // flip button
    _flipButton = [UIButton buttonWithType:UIButtonTypeCustom];

    UIImage *flipImage = [UIImage imageNamed:@"capture_flip"];
    [_flipButton setImage:flipImage forState:UIControlStateNormal];

    CGRect flipFrame = _flipButton.frame;
    flipFrame.size = CGSizeMake(25.0f, 20.0f);
    flipFrame.origin = CGPointMake(10.0f, CGRectGetHeight(view.bounds) - 10.0f);
    _flipButton.frame = flipFrame;

    [_flipButton addTarget:self action:@selector(_handleFlipButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_flipButton];
}

#pragma mark - view lifecycle



- (void)viewWillAppear:(BOOL)animated
{

    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

    [self _resetCapture];
    [[PBJVision sharedInstance] startPreview];
}
#导入“PBJViewController.h”
#导入“PBJVision.h”
#导入“PBJStrobeView.h”
#进口
#进口
#进口
@界面UIButton(ExtendedHit)
-(BOOL)pointInside:(CGPoint)pointwithevent:(UIEvent*)event;
@结束
@实现UIButton(ExtendedHit)
-(BOOL)pointInside:(CGPoint)pointwithevent:(UIEvent*)event
{
CGRect RelativeName=自边界;
UIEdgeInsets HITTESTEDGEENSETS=UIEdgeInsetsMake(-35,-35,-35,-35);
CGRect hitFrame=UIEDGEINSETINSETRECT(相对名称,hitTestEdgeInsets);
返回CGRectContainsPoint(hitFrame,point);
}
@结束
@接口PBJViewController()<
UIgestureRecognitzerDelegate,
PBJVisionDelegate,
UIAlertViewDelegate>
{
UIView*视图;
PBJStrobeView*_选通视图;
UIButton*\u doneButton;
UIButton*\u flipButton;
UIView*_预览视图;
AVCaptureVideoPreviewLayer*\u previewLayer;
mpmovieplayervewcontroller*播放器控制器;
MPMoviePlayerController*电影播放器;
UILabel*_说明书标签;
UILabel*股票代码;
n定时器*定时器;
//NSDate*起始日期;
n时间间隔起始日期;
整小时,分,秒;
int secondsLeft;
整数计数器;
int剩余时间;
int i;
NSTimeInterval elapsedTime;
UILongPressGestureRecognitor*\U LongPressGestureRecognitor;
布卢录音;
布尔跑;
阿拉塞特图书馆*_资产图书馆;
__块NSDictionary*\u currentVideo;
//NSTimeInterval编码。。
int curr分钟;
int curr秒;
国际货币小时;
国际分钟;
NSTimeInterval secondsAlreadyRun;
n时间间隔开始时间;
NSDate*开始日期1;
}
//@属性(非原子,保留)IBUIView*containerView;
@属性(强,非原子)MPMoviePlayerController*moviePlayerController;
@属性(非原子,强)NSString*视频路径;
@结束
@PBJViewController的实现
//@合成容器视图;
@综合电影播放控制器;
@综合视频路径;
#pragma mark-init
/*-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
//计数器=0;
//ticker.text=[NSString stringWithFormat:@“%d”,计数器];
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
_assetLibrary=[[AlassetLibrary alloc]init];
//[自我设置];
}
回归自我;
}*/
-(CDVPlugin*)使用WebView初始化:(UIWebView*)WebView
{
self=(PBJViewController*)[super initWithWebView:theWebView];
如果(自我){
_assetLibrary=[[AlassetLibrary alloc]init];
}
回归自我;
}
/*-(无效)viewDidLoad
{
webView=[[UIWebView alloc]init];
//注册UIWebViewDelegate,以便调用shouldStartLoadWithRequest(下一个函数)
webView.delegate=self;
}*/
-(无效)解除锁定
{
[UIApplication sharedApplication].idleTimerDisabled=否;
_LongPressGestureRecognitor.delegate=nil;
[super dealoc];
}
//-(无效)\u设置
-(void)_setup:(NSMutableArray*)paramArray with dict:(NSMutableDictionary*)选项;
{
NSLog(@“是从主屏幕btn单击继承”);
运行=错误;
secondsLeft=67;
view=[[UIView alloc]initWithFrame:CGRectMake(0,032032420)];
view.backgroundColor=[UIColor blackColor];
view.autoresizingMask=uiviewsautoresizingflexiblewidth | uiviewsautoresizingflexiblewhight;
CGFloat VIEWWITH=CGRECTGETWITH(view.frame);
//完成按钮
_doneButton=[UIButton按钮类型:UIButtonTypeCustom];
_doneButton.frame=CGRectMake(视图宽度-20.0f-20.0f、20.0f、20.0f、20.0f);
UIImage*buttonImage=[UIImage ImageName:@“capture_yep”];
[_donebuttonsetimage:buttonImage for state:UIControlStateNormal];
[_donebuttonaddtarget:self action:@selector(_handleDoneButton:)for controlEvents:UIControlEventTouchUpInside];
[视图添加子视图:_doneButton];
//经过的时间和红点
_strobeView=[[PBJStrobeView alloc]initWithFrame:CGRectZero];
CGRect strobeFrame=\u strobeView.frame;
strobeFrame.origin=CGPointMake(15.0f,15.0f);
_strobeView.frame=strobeFrame;
[视图添加子视图:_选通视图];
//预演
_previewView=[[UIView alloc]initWithFrame:CGRectZero];
_previewView.backgroundColor=[UIColor blackColor];
CGRect previewFrame=CGRectZero;
previewFrame.origin=CGPointMake(0,60.0f);
CGFloat previewWidth=view.frame.size.width;
previewFrame.size=CGSizeMake(previewWidth,previewWidth);
_previewView.frame=previewFrame;
//添加AV层
_previewLayer=[[PBJVision sharedInstance]previewLayer];
CGRect previewBounds=\u previewView.la