代码之家  ›  专栏  ›  技术社区  ›  petert

rubyonrails解决方案可以异步通知iPhone应用程序更新吗?

  •  0
  • petert  · 技术社区  · 15 年前

    简而言之,我有一个遗留应用程序,它可以读取和写入图像集合。此应用程序还使用sqlite数据库在需要时帮助引用正确的图像文件。

    我想做的是让一个iPhone和/或iPad应用程序浏览图片,但也能够看到更新和其他图片 没有

    isrubyonrailstheanswer 到目前为止,我显然已经有了(遗留的)linux应用程序,它可以生成图像并更新数据库。我还在linux应用程序中嵌入了一个bonjour服务,以允许iPhone应用程序连接sqlite数据库中的缩略图并对其进行最新浏览。棘手的是,我意识到,当数据库被远程更改时,iPhone应用程序需要启动来更新其图像。

    实际上,我认为通过RubyonRails应用程序,它可以提供一个RESTful服务来访问全尺寸(加上缩略图)图像,从而允许从sqlite数据库中删除缩略图图像—数据库可能有10000多个条目,因此不希望数据库不必要地增长。

    任何提示或资源将是伟大的。

    更新: 我又仔细考虑了一下问题的措辞。我想我在想我是否能得到 轨道

    2 回复  |  直到 15 年前
        1
  •  1
  •   marshally    15 年前

    我能想到的最简单的解决方案是对RESTful服务执行一个操作,从数据库中提取最近修改的日期。定期从你的iPhone应用程序中查询,然后刷新列表。

    例如,如果为图像创建脚手架:

    rails generate scaffold Image name:string filename:string # fill in the other attributes you need
    

    注意:您必须将遗留数据库同步到此Rails表

    然后,每个图像对象都会自动创建一个“updated\u at”属性。

    class ImagesController < ApplicationController
      # GET /images
      # GET /images.xml
      def index
        @images = Image.all
    
        respond_to do |format|
          format.html # index.html.erb
          format.xml  { render :xml => @images }
        end
      end
    
      # GET /images/1
      # GET /images/1.xml
      def show
        @image = Image.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @image }
        end
      end
    
      def newest
        @image = Image.find(:last, :order => :updated_at)
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @image }
        end
      end
    
      # more methods down here
    end
    

    YourAppName::Application.routes.draw do
      match 'images/newest' => 'images#newest'
      resources :images
    end
    

    现在,你可以从iPhone应用程序中提取一个XML文件,用这个URL描述你最近的图片

    http://localhost:3000/images/newest.xml
    

    解析出最近更新的时间,并将其与上次刷新日期进行比较。

        2
  •  1
  •   jv42    15 年前

    这实际上取决于您希望在应用程序中提供什么。您只需安排从应用程序到服务器(可能是Ruby应用程序)的请求,就可以轮询更新。这可能是最简单的解决办法。