我无法使用CDVPlugin从phonegap 2.7.0中的javascript访问本机iOS?

拉曼

我正在使用iOS 6的xcode 4.5.2中的phonegap 2.7.0 Web应用程序。在我的Web应用程序中包含六秒钟的视频录制选项。因此,我从“ https://github.com/piemonte/PBJVision完成了此过程

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

因此,我将PBJViewController.h和PBJViewController.m,PBJStrobeView.h和PBJStrobeView.m,PBJVisionUtilities.h和PBJVisionUtilities.m以及最后的PBJVision.h和PBJVison.m文件放在了plugins文件夹中。

然后,我创建一个JavaScript文件并将其命名为PBJViewController.js并添加到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.htm l

  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.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];
}

在这里,我面临警告消息“ CDVPlugin”可能无法响应“ viewWillAppear:”,因为我将CDVPlugin替换为UIViewController“ @interface PBJViewController:CDVPlugin”

我在config.xml文件中包含了插件的名称和值,

config.xml

这些是我的示例代码之一。我的问题是直到无法获得所需的输出。

请给出一些建议或结果。

卡利亚尼·普瓦瓦达(kalyani puvvada)

您可以尝试这样调用插件方法 cordova.exec(null, null, "PBJViewController", "_setup", [])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

当我对Ionic使用“ vw”指标时,CSS无法在iOS 7.x上正确呈现(PhoneGap)

在Windows 7中无法删除文件(2)

TableViewCell子视图在IOS 7中无法访问

在form2中无法访问在form1中创建的公共textBox7

使用NSBundle访问iOS7中的资产

展示Game Center时,iOS 6 EXC_BAD_ACCESS(代码= 2,地址= 0x15),但在iOS 7+中可以使用

Angular7中的ng2-dragula无法编译

SKCropNode在Xcode 7 + Swift 2中无法正常工作

我想在VirtualBox的CentOS 7中使用2个eth设备来设置bond0接口吗?

无法在iOS 7上将InAppBrowser插件用于Phonegap 3.1

在Symfony 2(.7)中禁用不推荐使用的警告

在Delphi 7中使用2个目录输出?

使用iOS 7,PhoneGap和jQuery Mobile进行怪异的滚动

无法从EC2上的Centos7网站访问S3中的文件

使用Angular 7无法在子组件中访问子行

PromiseKit无法使用Swift 2和Xcode 7进行编译

Android:我正在使用AppCompatv7库,但是无法访问其任何图标?

2月1日之后,不再可以在PhoneGap上开发iOS 7应用了吗?(Xcode 5和iOS 7 SDK限制!)

iOS8 Retina @ 2x图像无法像iOS7那样缩放?

无法使SWRevealViewController工作(Swift 2,Xcode 7)

无法在iOS7上使用scrollsToTop

UIScreen.mainScreen()。nativeBounds.height在使用Xcode 7 / Swift 2,目标iOS7时不起作用

在go lang中,为什么是7?断言(5 ^ 2 == 7)

无法在Phonegap中使用本机JavaScript Array函数

AlertView无法在ios7中旋转?

Xcode 7,Swift 2中的Gmail API iOS

设备上的XCode7 beta2和iOS8.4无法正常工作

无法访问分区-Windows 7中的访问被拒绝

我无法在EP121平板电脑上的CentOS 7中使用触摸屏