pebbleCentral:watchDidConnect never gets called on iOS - ios

I have an old Pebble Classic watch, upgraded to latest firmware (3.8.2) and using latest Pebble-SDK.
I have followed the few simple steps to install SDK, setup an Xcode project and adding the code to initialise and connect:
https://developer.getpebble.com/guides/mobile-apps/ios/
My problem is, that the delegate method pebbleCentral:watchDidConnect never gets called!
I am using the Pebble Time app on the iPad to install the watchApp in the watch, so I know the iPad is connected to the watch. The same iPad runs the iOS app, which apparently does not discover the watch.
I have tried to import an old test project from a colleague, who had it running a year or two ago. Same watch, same watchApp, but of course older firmware and SDK versions. Same result...
I think the documentation on the pebble site is quite simple and easy to follow. However, I feel I am missing some explanations of how and when this watchDidConnect is supposed to be triggered.
I am most likely missing some simple step somewhere, but I am quite lost in where to look!
Any ideas are welcome!
EDIT: My code looks like this:
ViewController.h:
#import <UIKit/UIKit.h>
#import PebbleKit;
#interface ViewController : UIViewController<PBPebbleCentralDelegate>
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) PBWatch* connectedWatch;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[PBPebbleCentral defaultCentral].delegate = self;
[[PBPebbleCentral defaultCentral] run];
NSLog(#"Pebble initialised");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidConnect (PBWatch*)watch isNew:(BOOL)isNew {
NSLog(#"Pebble connected: %#", [watch name]);
self.connectedWatch = watch;
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidDisconnect:(PBWatch*)watch {
NSLog(#"Pebble disconnected: %#", [watch name]);
if ([watch isEqual:self.connectedWatch]) {
self.connectedWatch = nil;
}
}
#end

Are you calling the -run method, after setting up your Pebble central? I noticed that the code snippet in the link you posted does not show the central's delegate being set.
[PBPebbleCentral defaultCentral].delegate = self; // Set your delegate
[PBPebbleCentral defaultCentral].appUUID = [[NSUUID alloc] initWithUUIDString:#"Your Pebble App UUID"]; // Set the app UUID
[[PBPebbleCentral defaultCentral] run]; // Call -run on the central

Related

Cordova iOS : Add method call in AppDelegate.m

I am building an app with cordova/ionic for iOS
For multiple reasons we have to put code inside generated application() of AppDelegate.m.
I allready found some similar question, but no answer yet.
https://stackoverflow.com/questions/36792158/cordova-phonegap-ios-modify-generated-appdelegate
There is a way to do it properly with some overloading or extending ?
The simple answer is "I can edit the AppDelegate.m" but since it's a generated file in the project, i can not do it.
Any ideas ?
Maybe you can use runtime to add new method in AppDelegate.m
for example
#interface testViewController (){
AppDelegate *m_appDelegate;
}
#implementation testViewController
- (void)viewDidLoad {
[super viewDidLoad];
m_appDelegate = [AppDelegate new];
// add new method in AppDelegate.m
[self addMethod];
// call new method in AppDelegate.m
[m_appDelegate performSelector:#selector(join)];
}
- (void)addMethod{
BOOL addSuccess = class_addMethod([AppDelegate class], #selector(join), (IMP)happyNewYear, "v#:");
}
void happyNewYear(id self,SEL _cmd){
NSLog(#"new method");
}
-(void)join{
NSLog(#"in the join %s",__func__);
}
hope it helps.

watch kit extension connect using SQLite

I need help how to connect my SQLite database to my watchkit app extension. Im not much familiar in using sqlite with cell rows. Any easy sample codes will be a great help thanks. Below are sample arrays i used for example.
#import "ICBQuoteSource.h"
#implementation ICBQuoteSource
+(NSArray *)quoteDictionary {
NSMutableArray *quotes = [NSMutableArray new];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"I came here to drink milk and kick ass... and I've just finished my milk."}];
[quotes addObject:#{#"characterImage": #"roy", #"characterName": #"Roy", #"quote": #"Hello, IT, have you tried turning it off and on again?"}];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"Did you see that ludicrous display last night?"}];
[quotes addObject:#{#"characterImage": #"denholm", #"characterName": #"Denholm", #"quote": #"That's the sort of place this is, Jen. A lot of sexy people not doing much work and having affairs."}];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"This Jen is the Internet"}];
return [NSArray arrayWithArray:quotes];
}
#end
#import "InterfaceController.h"
#import "ICBQuoteSource.h"
#import "rowController.h"
#interface InterfaceController()
#property (nonatomic, strong) NSArray *quotes;
#end
#implementation InterfaceController
- (void)awakeWithContext:(id)context
{
[super awakeWithContext:context];
// Get quotes
self.quotes = [ICBQuoteSource quoteDictionary];
// Set number of table Row
[self.table setNumberOfRows:self.quotes.count withRowType:#"Row Controller"];
// Set row properties
for (NSDictionary *quote in self.quotes) {
rowController *quoteRow = [self.table rowControllerAtIndex:[self.quotes indexOfObject:quote]];
[quoteRow.englishTxtLabel setText:quote[#"characterName"]];
[quoteRow.translationTxtLabel setText:quote[#"quote"]];
}
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
#end
You haven't actually stated what the problem is...so let me attempt to guess. I'm assuming that the rows are not showing up properly in your table. What I would suggest trying is moving your row set up logic into willActivate. This is something I found when working with tables in Xcode 6.2b5. You would not get the appropriate behavior in awakeWithContext(:).
Hopefully that helps lead you in the right direction. If this isn't the actual problem you are having, then please edit your question and I'll edit my answer accordingly.

GPUImage failing the CVPixelBufferGetPlaneCount check on iOS

I'm currently bringing a legacy project up from iOS 5/6 to iOS 6/7.
Part of this project involves taking a picture using the GPUImage library, processing it with a crop filter, then optionally adding some saturation and blur effects. I am currently using version 0.1.2 installed via cocoa pods.
The problem I am having is that when I try to capture an image from the camera, I hit the following assert in GPUImageStillCamera.m line 254
if (CVPixelBufferGetPlaneCount(cameraFrame) > 0)
{
NSAssert(NO, #"Error: no downsampling for YUV input in the framework yet");
}
where cameraFrame is a CVImageBufferRef
I have reproduced the code where this is called and move it to another project, where it works perfectly.
Once I moved this reproduced class back into the main project, I was hitting the assert every time.
Things I've ruled out with my own debugging
64bit (it’s happening on both)
different lib version
initial object setup / code / usage
This has lead me to believe that perhaps it might be a project setting that I've over looked. Any help or even a pointer in the right direction would be very very welcome. I've spent a good 1-2 days on this now and am still entirely lost!
I've included the stripped down class below which shows the general use.
#import "ViewController.h"
#import "GPUImage.h"
#import "ImageViewController.h"
#interface ViewController ()
#property (nonatomic, strong) IBOutlet GPUImageView *gpuImageView;
#property (nonatomic, strong) GPUImageStillCamera *camera;
#property (nonatomic, strong) GPUImageCropFilter *cropFilter;
#end
#implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setupCameraCapture];
}
- (void)setupCameraCapture
{
if (self.camera) {
return;
}
self.cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0, 1, 0.5625)];
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
self.camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
}
else {
self.camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionFront];
}
self.camera.outputImageOrientation = UIInterfaceOrientationPortrait;
NSError *error = nil;
[self.camera.inputCamera lockForConfiguration:&error];
[self.camera.inputCamera setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[self.camera.inputCamera setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
if ([self.camera.inputCamera respondsToSelector:#selector(isLowLightBoostSupported)]) {
BOOL isSupported = self.camera.inputCamera.isLowLightBoostSupported;
if (isSupported) {
[self.camera.inputCamera setAutomaticallyEnablesLowLightBoostWhenAvailable:YES];
}
}
[self.camera.inputCamera unlockForConfiguration];
[self.camera addTarget:self.cropFilter];
[self.cropFilter addTarget:self.gpuImageView];
[self.camera startCameraCapture];
}
- (IBAction)capturePressed:(id)sender
{
[self.camera capturePhotoAsImageProcessedUpToFilter:self.cropFilter withCompletionHandler:^(UIImage *image, NSError *error) {
// do something with the image here
}];
}
#end
The actual culprit was a swizzled method found by my colleague Marek. Hidden away in the depths of the old codebase. The above code works fine.
Lesson: if you really have to swizzle something, make sure you leave proper documentation for the future devs.

JMImageCache in a simple test app crashes with EXC_BAD_ACCESS

In Xcode 5.0.2
I create a blank single view app for iPhone,
then add a "male.png" image to the project,
drag a UIImageView to the storyboard
and finally add the following code to the viewDidLoad:
_imageView.image = [UIImage imageNamed:#"male.png"];
This works well:
Then I add the 4 files from JMImageCache project and change the ViewController.m to:
#import "ViewController.h"
#import "JMImageCache.h"
static NSString* const kAvatar = #"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
placeholder:[UIImage imageNamed:#"male.png"]];
}
#end
Unfortunately, this results in app crash with the error message Thread 1: EXC_BAD_ACCESS:
At his webpage Jake Marsh (the author of JMImageCache) notes:
JMImageCache purposefully uses NSString objects instead of NSURL's to make things easier and cut down on [NSURL URLWithString:#"..."] bits everywhere. Just something to notice in case you see any strange EXC_BAD_ACCESS exceptions, make sure you're passing in NSString's and not NSURL's.
But (as an iOS programming newbie) I don't understand, what exactly does Mr. Marsh mean - since his file UIImageView+JMImageCache.m declares the 1st argument for the public method as NSURL:
- (void) setImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholderImage {
[self setImageWithURL:url key:nil placeholder:placeholderImage];
}
Is the note maybe outdated and how could I fix my app?
That's a bug in JMImageCache. setImageWithURL:key:placeholder:completionBlock: calls itself, exhausting the stack.
To work around the bug, call the longer form of the method:
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
key:nil
placeholder:[UIImage imageNamed:#"male.png"]
completionBlock:nil
failureBlock:nil];
Or, use an older version of the library (e.g. 0.4.0). Looks like the bug was introduced in 1af09be78a.

having problems running unit tests in xcode after updating cocapods

Well, I updated cocoapods, added a new unit test pod that I wanted to try out, and I am unable to run even the most simple unit test.
It doesn't seem to be an issue with the pod but probably after I updated cocoapods to the newest version then did pod update.
Here's the error I get, basically the error is when I try and pull in any class from my main target into my tests.
a full size version: http://i.stack.imgur.com/x5EQP.png
uncomment the lines that are commented out and I get the error, otherwise cmd+U will run and succeed.
#import "AppDelegateTests.h"
//#define EXP_SHORTHAND
//#import "Expecta.h"
//#import "AppDelegate.h"
#implementation AppDelegateTests {
// AppDelegate *_appDelegate;
}
- (void)setUp
{
[super setUp];
// _appDelegate = [[AppDelegate alloc] init];
}
- (void)test_rootViewController_should_be_SplitViewController {
// expect(1).to.equal(1);
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
#end

Resources