Note that there are some explanatory texts on larger screens.

plurals
  1. POABPersonViewController error with RubyMotion
    primarykey
    data
    text
    <p>I am having trouble using the <code>ABPersonViewController</code> with RubyMotion. The error I'm getting is </p> <blockquote> <p>Objective-C stub for message <code>setDisplayedPerson:' type</code>v@:^v' not precompiled. Make sure you properly link with the framework or library that defines this message.</p> </blockquote> <p>I suspect this is due to RubyMotion not casting to the type IOS expects. I think <code>ABPersonCreate()</code> is returning a <code>CFType</code> but the <code>displayedPerson</code> setter is expecting it to be cast as a <code>ABRecordRef</code> (that's just a guess from the error messages)</p> <p>Here's the sample code to see the problem (based on Apple's QuickContacts sample):</p> <pre><code>#Rakefile $:.unshift("/Library/RubyMotion/lib") require 'motion/project' Motion::Project::App.setup do |app| # Use `rake config' to see complete project settings. app.name = 'contacts' app.frameworks += ['AddressBook', 'AddressBookUI'] end </code></pre> <p>and</p> <pre><code># app/app_delegate.rb class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame) window.rootViewController = UINavigationController.alloc.init window.rootViewController.wantsFullScreenLayout = true window.makeKeyAndVisible true # This works add_person('Alex', 'Rothenberg') # This fails (is it a type casting problem?) show_person_view_controller('Rothenberg') end def show_person_view_controller(name) anError = nil address_book = ABAddressBookCreate(); people = ABAddressBookCopyPeopleWithName(address_book, name); person = people.first picker = ABPersonViewController.alloc.init.autorelease picker.personViewDelegate = self puts "Should this be an AddressBookRef? #{person.inspect}" # =&gt; #&lt;__NSCFType:0x8c3bec0&gt; picker.displayedPerson = person # The previous line fails puts "We never reach this line!" self.navigationController.pushViewController(picker, animated:true) end def add_person(first_name, last_name) error = nil contact = ABPersonCreate() ABRecordSetValue( contact, KABPersonFirstNameProperty, first_name, error ) ABRecordSetValue( contact, KABPersonLastNameProperty, last_name, error ) address_book = ABAddressBookCreate() ABAddressBookAddRecord( address_book, contact, error ) ABAddressBookSave( address_book, error ) end end </code></pre> <p>When you run it we are able to add to the address book in the <code>add_person</code> method but it fails in <code>show_person_view_controller</code> on the line <code>picker.displayedPerson = person</code></p> <pre><code>$ rake Build ./build/iPhoneSimulator-5.1-Development Simulate ./build/iPhoneSimulator-5.1-Development/contacts.app Should this be an AddressBookRef? #&lt;__NSCFType:0x8da2900&gt; Objective-C stub for message `setDisplayedPerson:' type `v@:^v' not precompiled. Make sure you properly link with the framework or library that defines this message. </code></pre> <p>Any suggestions would be appreciated</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload