vinnycoyne.com
Magical adventures in nerdery.

10 November 2010

BTLog - Bluetooth NSLog() for iOS Devices

[This is an old post that I've brought over from the old vinnycoyne.com blog. I've updated the download links to point to the repo over on GitHub]

I'm currently testing & debugging an iOS app, which is logging quite a bit of location-related data using NSLog(). This is fine when I'm tethered to my MacBook Pro, but it's not so great for testing in the field.

So, rather that lugging around the MBP, I decided to make use of the various iOS devices I have lying around and turn them into a console for NSLog() data. It's pretty basic right now (and not exactly production-ready), but it works well.

I should also note that the portion of code which overrides NSLog() came from c99koder's lastfm-iphone source code.

Add BTLog to your own app:

  1. Download the BTLog project files here and add BTLog.h and BTLog.m to your app's Xcode project.

  2. Add GameKit.framework to your Xcode project.

  3. In main.m, add: #include "BTLog.h" Note that that's include and not import!

  4. In your app delegate's header file: #import "BTLog.h" and in your declarations (in the same file): BTLog *btLogger;

  5. In your app delegate's implementation (.m) file:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        btLogger = [[BTLog alloc] initWithDelegate:self];

        // ...

}

(you can put this anywhere, but I find it handiest here.)

Note that the delegate is set to self — we're doing this so that the following method gets called — put it anywhere in your app delegate's .m file:

-(void)logStringToRemoteDevice:(NSString *)string {

        if (string.length > 0 && btLogger) {
                [btLogger logString:string];
        }
}
  1. Download the BTLog project here (if you haven't already) — build it in Xcode & install it onto any iOS device running 3.x or higher. Launch your own app (modified with the steps above) on your testing device.

Connect the two apps over Bluetooth and you should see your NSLog() strings appear in the BTLog app.

If you spot any bugs or have any suggestions for improvement, drop me a line.

Feel free to use this in any app that you're developing, but don't forget to remove the code once you begin building for production!


← Home | 🔗 Permalink | Follow me on Mastodon | RSS Feed