首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rubymotion & RestKit

Rubymotion & RestKit
EN

Stack Overflow用户
提问于 2012-05-25 03:25:00
回答 1查看 827关注 0票数 2

是否有人让Rubymotion使用RestKit的RKObjectManager并成功地从服务器加载了一些对象?我在这方面有很多麻烦。我有RestKit-- RKClient很好用。我可以成功地得到和张贴,这是很好的。但是我不能用RKObjectManager加载资源。我的Rakefile看起来是这样的

代码语言:javascript
复制
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'

Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'RestKitTest'
  app.frameworks += %w(CoreData CFNetwork Security MobileCoreServices SystemConfiguration QuartzCore)
  app.vendor_project('vendor/RestKit', :xcode, :target => 'RestKit', :headers_dir => '../Headers/RestKit/')
end

我的应用程序代表如下:

代码语言:javascript
复制
class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
    @window.rootViewController = TestViewController.alloc.init
    @window.rootViewController.wantsFullScreenLayout = true
    @window.makeKeyAndVisible
    true
  end
end

我的存根TestViewController看起来是这样的:

代码语言:javascript
复制
class TestViewController < UIViewController
  def init
    super

    puts "checkpoint 1"

    manager = RKObjectManager.managerWithBaseURLString "http://mlpong.herokuapp.com"
    puts "checkpoint 2"

    mapping = RKObjectMapping.mappingForClass League.class
    puts "checkpoint 3"

    # mapping.mapAttributes("id", "name", "url", nil)
    mapping.mapKeyPath("id", toAttribute:"id")
    mapping.mapKeyPath("name", toAttribute:"name")
    mapping.mapKeyPath("url", toAttribute:"url")
    puts "checkpoint 4"

    manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
    puts "checkpoint 5"

    manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
    puts "checkpoint 6"

    self
  end

  def objectLoader(loader, didFailWithError:error)
    puts "failed with error: #{error.domain}"
  end

  def objectLoader(loader, didLoadObjects:objects)
    puts "success!"
  end
end

不幸的是,您不能使用这个精确的代码进行测试,因为您需要我的令牌作为站点。

RKObjectMapping类的mapAttributes方法(上面注释掉)无法工作。如果我离开它,应用程序会输出1-3个检查点,然后是怪物。rake --跟踪揭示了这一点:

代码语言:javascript
复制
** Invoke default (first_time)
** Invoke simulator (first_time)
** Invoke build:simulator (first_time)
** Execute build:simulator
** Execute simulator
/usr/bin/defaults write com.apple.iphonesimulator "SimulateDevice" "'iPhone'"
DYLD_FRAMEWORK_PATH="/Applications/Xcode.app/Contents/Developer/../Frameworks":"/Applications/Xcode.app/Contents/Developer/../OtherFrameworks" /Library/RubyMotion/bin/sim 2 1 5.1 "/Applications/Xcode.app/Contents/Developer" "./build/iPhoneSimulator-5.1-Development/RestKitTest.app"
checkpoint 1
checkpoint 2
checkpoint 3
(main)> ** Execute default

如果我注释掉mapAttributes行,并使用另一个(更长的)对象映射版本(在检查点4之前未注释的3行),则可以通过所有检查点,但当我使用rake -trace时会收到此结果。

代码语言:javascript
复制
** Invoke default (first_time)
** Invoke simulator (first_time)
** Invoke build:simulator (first_time)
** Execute build:simulator
** Execute simulator
/usr/bin/defaults write com.apple.iphonesimulator "SimulateDevice" "'iPhone'"
DYLD_FRAMEWORK_PATH="/Applications/Xcode.app/Contents/Developer/../Frameworks":"/Applications/Xcode.app/Contents/Developer/../OtherFrameworks" /Library/RubyMotion/bin/sim 2 1 5.1 "/Applications/Xcode.app/Contents/Developer" "./build/iPhoneSimulator-5.1-Development/RestKitTest.app"
checkpoint 1
checkpoint 2
checkpoint 3
checkpoint 4
checkpoint 5
checkpoint 6
(main)> terminate called without an active exception** Execute default

我整天都在犯这些错误。如果有人知道,请告诉我。非常感激的帮助。谢谢,

巴春

EN

回答 1

Stack Overflow用户

发布于 2013-12-15 07:38:09

你已经调用了一些不存在的方法。

代码语言:javascript
复制
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"

manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"

应该是的。

代码语言:javascript
复制
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", mapping:mapping, delegate:self)
puts "checkpoint 5"

参见我在以下网站上找到的类似问题:loadObjectsAtResourcePath (RestKit)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10748094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档