Shazron's Cordova (aka PhoneGap) Blog

at Adobe Systems Inc.

Automatic Reference Counting (ARC) and Cordova Plugins

with 11 comments

With the release of Cordova 2.1.0, CordovaLib will have been fully migrated to use Automatic Reference Counting (ARC). In a nutshell, ARC is automatic memory management for Objective-C objects and blocks (simply – you don’t have to worry about retains and releases for the most part).

What does it mean for your third-party Cordova iOS plugins?

Nothing1, if your project itself does not support ARC, and the default project template does not support ARC for Cordova iOS 2.1.0.

If you do upgrade your project itself to ARC through running the Xcode migration wizard from the menu: Edit -> Refactor -> Convert to Objective-C ARC… (then de-select libCordova.a) then you need to be aware that your plugins need to be upgraded since 99% of the plugins out there are not ARC compatible yet.

How do you get your plugin upgraded?

  1. The plugin author should upgrade the plugin to conditionally support ARC (through the __has_feature(objc_arc) macro) which would maintain compatibility
  2. You can upgrade them yourself using the Xcode migration wizard (Edit -> Refactor -> Convert to Objective-C ARC…) and selectively choose the plugin files only
  3. Don’t upgrade but set a compiler flag for your .m file in your Target settings to not compile your plugin for ARC. Select the Build Phases tab, expand the “Compile Sources” list, and select your .m file. Double-click in the “Compiler Flags” column, and enter the value -fno-objc-arc

[1] In the rare case that you encounter a plugin that is ARC only and you need to use it in your non-ARC project, do step 3 above but use the compiler flag -fobjc-arc instead.

Written by shazron

September 5, 2012 at 1:41 am

11 Responses

Subscribe to comments with RSS.

  1. Hi, any ETA on 2.1? I know it was originally scheduled to 04 Sep.? Thanks.

    Grig

    September 8, 2012 at 10:36 pm

    • It will be the week of Sept 10th. Last minute issues have cropped up, so the best I can give is that 1 week timeframe.

      shazron

      September 9, 2012 at 6:08 am

      • Have you got an updates ETA since the week op the 10th of Sept has already passed?

        Aidan Langelaan

        September 21, 2012 at 12:25 pm

      • Sorry about this. This was supposed to be our first Apache release but there are two rounds of votes needed (each lasting 72 hours) that we didn’t account for.

        Instead of waiting for Apache to approve the official release, we will release the same tagged identical source as 2.1 on phonegap.com – we are preparing it today in fact (Fri Sept 21st 2012).

        shazron

        September 21, 2012 at 6:44 pm

      • We just tagged the 2.1.0 download in Github: https://github.com/phonegap/phonegap/tags

        shazron

        September 21, 2012 at 7:19 pm

      • Great! Thank you for the update. Will also have better support for iOS6?

        Aidan Langelaan

        September 21, 2012 at 6:48 pm

      • Yes for the most part, but 2.2.0 will be the update that fixes all of the remaining iOS 6 issues. This release was packaged before the iPhone 5 launch – so the next release irons out issues related to that as well.

        shazron

        September 21, 2012 at 6:51 pm

  2. Any new ETA? Thanks!

    Benjamin Hill

    September 20, 2012 at 6:05 pm

  3. Shazron, have you (or anyone else on the Cordova team) had the chance to review the MapKit plugin for ARC issues? I recently installed Cordova 2.3.0 for iOS and am using Xcode 4.5.2 (though the same problems happen with Xcode 4.6). When I follow the instructions at https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/MapKit to install the MapKit plugin, I get “Apple Mach-O Linker Errors”:

    Undefined symbols for architecture i386:
    “_MKCoordinateRegionMakeWithDistance”, referenced from:
    -[MapKitView setMapData:withDict:] in MapKit.o
    “_OBJC_CLASS_$_MKMapView”, referenced from:
    objc-class-ref in MapKit.o
    “_OBJC_CLASS_$_MKPinAnnotationView”, referenced from:
    objc-class-ref in MapKit.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I also posted about this in Phonegap Google Groups (https://groups.google.com/forum/#!topic/phonegap/o5obsAx9bqw).

    I also tried your suggestions above about updating the plugin to ARC, or to set the compiler flag, but Xcode says the MapKit.m file cannot be upgraded to ARC. And with the compiler flag I get a whole bunch of other ARC-related errors. Not sure what to do (other than drop the MapKit plugin and use a 3rd-party mapping solution, which wouldn’t be ideal).

    Thanks!

    Steve

    • Seems you managed to solve it in the GG 🙂 Which would have been my recommendation as well once I saw the errors.

      shazron

      February 8, 2013 at 2:59 pm


Leave a reply to shazron Cancel reply