Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question from newbie #2

Closed
damyrm opened this issue Dec 13, 2015 · 5 comments
Closed

Question from newbie #2

damyrm opened this issue Dec 13, 2015 · 5 comments

Comments

@damyrm
Copy link

damyrm commented Dec 13, 2015

Hi,

Thanks you for this great class.
But I'm a newbie and tried to use your lib today and result: camera flash start and stop directly on iphone 5c IOS 9.
Not sure what I did wrong.
My viewController.h:

import <UIKit/UIKit.h>

import "HeartRateDetectionModel.h"

@interface ViewController : UIViewController

  • (IBAction)Start:(id)sender;
    @Property (weak, nonatomic) IBOutlet UILabel *label;
    @EnD

and my viewController.m

import "ViewController.h"

import "HeartRateDetectionModel.h"

@interface ViewController ()
@EnD
@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }
  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
  • (IBAction)Start:(id)sender {
    HeartRateDetectionModel *hr = [[HeartRateDetectionModel alloc]init];
    hr.delegate = self;
    [hr startDetection];
    }
    -(void)heartRateStart {
    NSLog(@"started!");
    self.label.text = @"started!";
    }
    -(void)heartRateEnd {
    NSLog(@"Stopped!");
    self.label.text = @"started!";
    }
    -(void)heartRateUpdate:(int)bpm atTime:(int)seconds {
    NSLog(@"running!");
    self.label.text = @"running!";
    }@EnD

Like I said, still I newbie, any idea why flash just start and stop?

Thank you in advance for your help.

Dams

@lehn0058
Copy link
Owner

Did you get prompted for permission to use the camera? If permission is not given when the dialog is displayed, then the camera can't be used by the app. You can check the permissions under the settings app.

@damyrm
Copy link
Author

damyrm commented Dec 14, 2015

Thanks for your quick answer.
Did check in the settings but the camera's permission was given.
I'll try to start again from scratch with also an other device.

@damyrm
Copy link
Author

damyrm commented Dec 14, 2015

So tested on a fresh xcode installation, on a new git clone (+add previous code for viewController), on a new device with ios 9.2.
When I run:

  • (IBAction)Start:(id)sender {
    HeartRateDetectionModel *hr = [[HeartRateDetectionModel alloc]init];
    hr.delegate = self;
    [hr startDetection];
    }
    the flash starts, It ask me the authorisation to use for the camera: press OK,
    I get the delegate method firing:
    -(void)heartRateStart {
    NSLog(@"started!");
    self.label.text = @"started!";
    }
    The flash stop,
    Nothing else.

Settings privacy, camera enable for the project.
rerun the app, same flash for less a sec, label=started and nothing change.

tried with a device 7.1 (no cam permission), same result .

I'm pretty sure the problem comes from my side, but cannot find where.
Any other idea?

Thank you in advance.

@lehn0058
Copy link
Owner

I think I see your issue. HeartRateDetectionModel *hr is being released from memory right after you call start. You will need to keep an instance that stays around - probably as a property on the class your start method is in. Try something like this:

// At top of class file
@Propert (nonatomic, strong) HeartRateDetectionModel *hr;
...
...
...

  • (IBAction)Start:(id)sender {
    self.hr = [[HeartRateDetectionModel alloc]init];
    self.hr.delegate = self; [hr startDetection];
    }

@damyrm damyrm closed this as completed Dec 15, 2015
@damyrm damyrm reopened this Dec 15, 2015
@damyrm
Copy link
Author

damyrm commented Dec 15, 2015

It was exactly that.
Tested my heart rate with your app and the results are good.
Thank you for your help.

@damyrm damyrm closed this as completed Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants