RubyMotion的ABPersonViewController错误

时间:2012-06-06 20:02:03

标签: rubymotion

我在使用RubyMotion ABPersonViewController时遇到问题。我得到的错误是

  

消息setDisplayedPerson:' type v @:^ v'的Objective-C存根不是预编译的。确保正确链接定义此消息的框架或库。

我怀疑这是由于RubyMotion没有转换为IOS期望的类型。我认为ABPersonCreate()正在返回CFType,但displayedPerson setter期望将其转换为ABRecordRef(这只是对错误消息的猜测)

以下是查看问题的示例代码(基于Apple的QuickContacts示例):

#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

# 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}" # => #<__NSCFType:0x8c3bec0>
    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

运行时,我们可以使用add_person方法添加到地址簿,但show_person_view_controllerpicker.displayedPerson = person上的地址簿失败

$ rake
     Build ./build/iPhoneSimulator-5.1-Development
  Simulate ./build/iPhoneSimulator-5.1-Development/contacts.app
Should this be an AddressBookRef? #<__NSCFType:0x8da2900>
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.

任何建议都将不胜感激

1 个答案:

答案 0 :(得分:1)

从RubyMotion 1.12(运行sudo motion update)开始,这将正常工作。

  
      
  • 修正了执行接受的Objective-C方法的错误   CFType对象   会使程序崩溃(例如[ABPersonViewController setDisplayedPerson:])。
  •