1

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

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

我怀疑这是由于 RubyMotion 没有转换为 IOS 期望的类型。我认为ABPersonCreate()正在返回 aCFTypedisplayedPerson设置器期望它被转换为 a 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_controller就行了picker.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.

任何建议,将不胜感激

4

1 回答 1

1

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

  • 修复了执行接受 CFType 对象的 Objective-C 方法会导致程序崩溃的错误(例如 [ABPersonViewController setDisplayedPerson:])。
于 2012-06-19T01:57:23.530 回答