1

ABPersonViewControllerRubyMotionでの使用に問題があります。私が得ているエラーは

setDisplayedPerson:' typeメッセージv@:^v'のObjective-Cスタブはプリコンパイルされていません。このメッセージを定義するフレームワークまたはライブラリと適切にリンクしていることを確認してください。

これは、RubyMotionがIOSが期待するタイプにキャストされていないことが原因だと思います。私ABPersonCreate()はを返していると思いますCFTypeが、displayedPersonセッターはそれがとしてキャストされることを期待しています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.

任意の提案をいただければ幸いです

4

1 に答える 1

1

これは、RubyMotion 1.12 (実行) で正しく動作しますsudo motion update

  • CFType オブジェクトを受け入れる Objective-C メソッドを実行するとプログラムがクラッシュするバグを修正しました (例: [ABPersonViewController setDisplayedPerson:])。
于 2012-06-19T01:57:23.530 に答える