有没有人让Rubymotion使用RestKit的RKObjectManager并成功从服务器加载了一些对象?我遇到了很多麻烦。我有RestKit的RKClient运行良好。我可以成功发布,这很棒。但我无法使用RKObjectManager加载资源。我的Rakefile看起来像这样:
$:.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
我的app委托代码如下:
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看起来像这样:
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 --trace 揭示了这一点:
** 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时收到它 - 微量:
** 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
我整天都遇到这些错误。如果有人有任何想法,请告诉我。非常感谢。谢谢,
Pachun
答案 0 :(得分:0)
你已经调用了一些不存在的方法。
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
应该是。
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", mapping:mapping, delegate:self)
puts "checkpoint 5"
查看类似问题我找到了答案:loadObjectsAtResourcePath (RestKit)