Sharing MAMP between Two Computers

I use MAMP (mamp.info) as a local server setup on my Mac for developing web apps. My primary setup is a Mac Mini, but I also use a Macbook Pro for when I’m in a client’s office or working remotely. To keep the two in sync, I use Dropbox. This is straight-forward for documents and html/php files, but a bit more complicated for syncing databases between the two machines.

To sync the web files, I simply moved the htdocs folder from the MAMP folder to the Dropbox folder. In the MAMP app preferences, I changed the Document Root for the web server to point to the folder in Dropbox.

To sync the database files, I moved the ‘db’ folder to the Dropbox folder. I then created a Symbolic Link from the folder in Dropbox to the original location in the MAMP folder. This is done using the ‘ln’ command at the command prompt. In my case, the following command did the job:

ln -s /Users/stuart/Dropbox/MAMP/db/ /Applications/MAMP/

You should be able to edit this to suit your setup.

ShowFit Plugin Updated

Time:
05-Sep-20 10:36 am
Duration:
01:42:53
Distance:
23.64 km

I’ve just updated our WordPress Plugin for embedding Garmin .fit data files in your blog. The latest update improves the speed of rendering the maps and reduces the amount of data your blog downloads from external sites.

The latest version of the plugin can be downloaded from http://yellowfield.co.uk/downloads/showfit.zip, or from our GitHub repository https://github.com/tevendale/ShowFitFile

For details of the plugin, see our original blog post

If you’ve got any questions about this plugin or about getting your own plugin developed, please get in touch.

UITableView Pointer Support for iPad using Objective-C

In iPadOS 13.4, Apple introduced the Mouse support for iPads. Prior to this mouse support had kind-of worked with iPads – I’d tried connecting a USB mouse using the Camera adaptor – but it was a bit flaky and didn’t really provide any feedback on what was clickable.

Fast-forward to 13.4, and now we had a circular pointer and feedback when the pointer was over a clickable item.

For most controls, it was simply a case of adding isPointerInteractionEnabled=yes to the control. However, for some other controls, such as UITableCellView, some custom code was required.

When I attempted to add this to iSMARTtrain for iOS, most, if not all, of the code I found was for Swift. It took a bit of time figuring out how to convert this to Objective-C (and I wasn’t about to rewrite an entire class just to for pointer support!). Here’s the code in case it helps anyone else.

For UITableView

In the View Controller, add the delegate:

@interface YFTListViewTableController : UITableViewController <UIPointerInteractionDelegate>

In the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method, add

if (@available(iOS 13.4, *)) {
  if (cell.interactions.count == 0) {
    UIPointerInteraction *pointerInteraction = [[UIPointerInteraction alloc] initWithDelegate:self];
    [cell addInteraction:pointerInteraction];
  }
}

Where cell is the cell for the row

Add the delegate method to the class

- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region  API_AVAILABLE(ios(13.4)){
    UIPointerStyle *pointerStyle = nil;
    
    UIView *interactionView = interaction.view;
    if (interactionView) {
        UITargetedPreview *targetPreview = [[UITargetedPreview alloc] initWithView:interactionView];
        
        
        UIPointerEffect *hoverEffect = [UIPointerHoverEffect effectWithPreview:targetPreview];
        
        pointerStyle = [UIPointerStyle styleWithEffect:hoverEffect shape:nil];
    }
    return pointerStyle;
}

Cross-Platform Images in Core Data

In an upcoming-release of iSMARTtrain, I’ve added a profile picture for the user settings. To support the iOS version of iSMARTtrain (coming soon), this needed to work cross-platform in a Core Data document.

Transferring images between the two platforms in a common format seems rather complicated, as there’s no common image format that can be easily extracted from both NSImage and UIImage. In the end, I ended up saving the images on the Mac side as PNG files, which can be handled natively by UIImage on the iOS side.

Self‘ in these cases is a Core Data NSManagedObject

On the Mac Side:

Save the image:

- (void)saveProfileImage:(NSImage *)profile {
      NSData *imageData = [profile TIFFRepresentation];
      NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
      NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
      NSData *imagePNGData = [imageRep representationUsingType:NSBitmapImageFileTypePNG properties:imageProps];
      self.image = imagePNGData;
  }

Retrieve the image

- (NSImage *)profileImage {
      if (self.image) {
            NSData *imageData = self.image;
           NSImage *newImage = [[NSImage alloc] initWithData:imageData];
           return newImage;
       }
       return nil;
 }

On the iOS Side:

Save the image:

- (void)saveProfileImage:(UIImage *)profile {
       self.image = UIImagePNGRepresentation(profile);
}

Retrieve the image:

- (UIImage *)profileImage {
      if (self.image) {
            NSData *imageData = self.image;
            UIImage *newImage = [[UIImage alloc] initWithData:imageData];
            return newImage;
      }
       return nil;
 }

WordPress Plugin to show .fit files

I’ve recently finished writing a WordPress plugin to display .fit (Flexible and Interoperable Data Transfer) files. These are files from fitness devices, such as Garmin watches & bike computers. This is a personal project that I’ve wanted for quite a while. I’ve often posted in my personal blog (stuarttevendale.com) about the cycling, running & triathlon events I’ve taken part in, but including data from the event wasn’t straight-forward. While other plugins have existed to display routes from .gps file or other formats, this meant the additional hassle of converting the files. The data from the files also had to be entered manually.

For this plug-in, simply upload the .fit file to the media library in WordPress and add single shortcode to your post. The plugin has various options to set the colour of the route line, units (imperial or metric), and to determine in the map can be zoomed or not. The plugin also shows a summary of the event; start time, distance and time taken.

Download from: http://yellowfield.co.uk/downloads/showfit.zip

If you’re interested in using Yellow Field Technologies for developing your next WordPress plugin, please get in touch.

The plugin is based on LeafletJS maps and uses phpFITFileAnalysis from https://github.com/adriangibbons/phpFITFileAnalysis, php-geometry from https://github.com/gregallensworth/PHP-Geometry and https://github.com/pointhi/leaflet-color-markers.

Some Examples:

The Methlick Cycle Challengehttps://stuarttevendale.com/2019/07/19/methlick-cycle-challenge/

Show the basic route map + summary data using plugin defaults:

[showfitfile file = "2019-07-14-10-32-10.fit"]

Time:
14-Jul-19 10:32 am
Duration:
03:37:44
Distance:
63.14 km

Loch Ness Marathonhttps://stuarttevendale.com/2017/10/26/loch-ness-marathon/

Shows the route on an interactive map, with a blue route line & the session details in miles.

[showfitfile file = "Loch-Ness-Marathon.fit" interactive="yes" colour="blue" units="imperial"]

Time:
24-Sep-17 10:03 am
Duration:
05:17:03
Distance:
26.28 miles

NSScotland 2014

nsscotland-logoThis past weekend, I attended NSScotland in Edinburgh. The conference, in its 3rd year, is organised by Alan Francis and Paul Wilson, who also organised the Scottish Ruby conference. The venue for the conference was on the south side of Edinburgh in the Pollock Halls.

Spread over two days, the conference covered a good mix of technical and non-technical subjects, including iOS app testing at Facebook (Graham Lee), Computing’s Hidden Heroes (Emily Toop), and, the personal highlight for me, Eric Knapp’s talk on Helping Blind Musicians with an iOS App. Between talks, there was plenty of time for socialising and catching up with other developers.

On Saturday night, we were treated to chilli for dinner, cooked by Illegal Jacks, in a near-by Church Hall. As there was no connectivity in the hall, people were forced to talk to each other, rather than huddling over laptops!

On the Monday following the conference, Alan had organised a Swift tutorial, taught by Daniel Steinberg. The tutorial covered the basics of swift from the very beginning and progressed at a nice pace up to the more complicating features. Personally, some of the subjects covered in the final part of the tutorial made my head spin a bit, but this was due to my lack of computer science knowledge, rather than the instructor. At the end of the tutorial I was left with a good understanding of Swift, having never touched it before.

A big thank you to Alan and Paul for organising the conference, Daniel Steinberg for teaching the tutorial and Zonal and Karelia Software for their sponsorship. I’m already looking forward to next year!

NSPopover from NSToolbarItem

Recently, when working on the next release of iSMARTtrain, I wanted to display an NSPopover containing the various options when a button in the toolbar was clicked. I mean, how hard can that be? – I’d already done it in the iPad version of Ergophase. Trivial!

NSPopover from NSToolbarItem

Three hours later, it turns out, it’s not as straight-forward as I thought. Central to displaying an NSPopover is the following method call:-

 (void)showRelativeToRect:(NSRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(NSRectEdge)preferredEdge

Surely all I need to do is to get the view from the Toolbar button, pass it to this method, the popover’s displayed, and all is good with the world?

Well, unfortunately not.

For whatever reason, NSToolbarItem is inherited from NSObject, rather than NSControl, meaning that it has no View property that can be accessed (well, actually it does, but for the default button added in IB, view always returns Nil).

I posted my problem in Stackoverflow and, unusually, got no solution. Searching Apple’s developer forums turned up this post (http://devforums.apple.com/message/499986), which refered me to one of this year’s WWDC videos.

Once I’d seen that, everything became a bit clearer. The solution is to create an NSToolbarItem with a custom view containing an NSButton. When the button is clicked, pass the View of the button to the showRelativeToRect method, displaying the popover.

In the spirit of  http://xkcd.com/979, I’m posting a really simple example with the code on github (http://github.com/tevendale/ToolbarPopover). One slight issue with the current code is the way the button behaves when clicked, but I’m sure someone smarter than me will manage to fix that.

YFCalendarView – iPad Calendar Framework

YFCalendarView is our open-source framework for a full-screen iPad calendar. It’s loosely based on the Mac calendar framework LRCalendar (which seems to have largely disappeared from the ‘net).

It provides a full-screen monthly calendar, functionally similar to the iPad Calendar app ‘Month’ view.

YFCalendarSmall

Download the latest code from our Github repository: http://github.com/tevendale/YFCalendar

Project ANT – Live ANT+ Data on Your Mac

Project ANT is our new product from Yellow Field Technologies. It’s an application to enhance your turbo training or treadmill sessions. For use with any ANT+ Sport compatible power meter, heart rate monitor belt, speed or cadence sensor, it displays your data on your desktop or laptop Mac with a graph or video.

Screenshot

The data displayed in each field can be selected from a number of options, including average power and Phil Skiba’s xPower, RI and BikeScore™ metrics.

Displayoptions

Project ANT uses Garmin’s ANT+ USB stick to communicate with the ANT sensors.

The application is currently in the late stages of development, and the latest Beta can be downloaded from http://www.yellowfield.co.uk/projectant/. You can also join our mailing list at this page.

There are still a few features to be added to the application before final launch, including data export to tcx, csv and pwx formats, and session analysis.

Video image above, © Sufferfest.

iOS Debugging with Hardware

dockstubz from CableJive

If you’re developing an app which uses hardware that plugs into the 30-pin Dock Connector of the iPhone or iPad, then debugging in Xcode can become a bit of a problem. I’m working with Wahoo Fitness using their Fisica ANT+ device at the moment, and I was about to break out the soldering iron to make some sort of a pass-through connector when Chip from Wahoo mentioned using dockStubz from Cablejive.

This provides a male and female dock connector with a USB connector in the middle of the unit. This lets the iOS device be connected to a Mac with the hardware device installed, allowing breakpoints and the like to be set in Xcode.

It’s available directly from Cablejive in the US and from Amazon in the UK (and presumably the rest of Europe).