小编Jay*_*ane的帖子

MPNowPlayingInfoCenter defaultCenter不会更新或检索信息

我正在努力更新MPNowPlayingInfoCenter并遇到一些麻烦.我已经尝试了很多,以至于我不知所措.以下是我的代码:

    self.audioPlayer.allowsAirPlay = NO;

    Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) {

        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"series_placeholder"]];

        [songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:@"NCC" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];

        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


    }
Run Code Online (Sandbox Code Playgroud)

这不起作用,我也尝试过:

   [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
Run Code Online (Sandbox Code Playgroud)

试图让它从iPod应用程序中删除现有信息(或任何可能有信息的信息).另外,为了看看我是否能找到问题,我已经尝试检索应用启动时的当前信息:

  NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
  NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
  NSString *author = [info valueForKey:MPMediaItemPropertyArtist];

  NSLog(@"Currently playing: %@ // %@", title, author);
Run Code Online (Sandbox Code Playgroud)

我明白了 Currently playing: (null) // (null)

我对此进行了相当多的研究,以下文章对此进行了彻底的解释,但是,我仍然无法正常工作.我错过了什么吗?会有什么干扰吗?这是我的应用程序需要注册访问的服务(在任何文档中都没有看到这个)吗?

Apple的文档

更改锁定屏幕背景音频控件

现在播放信息被忽略

iphone mpmovieplayercontroller ios

28
推荐指数
1
解决办法
2万
查看次数

Rails 4和Devise - 通过JSON API进行用户注册

我正试图通过JSON注册一个设备用户但是继续得到一个 ActiveModel::ForbiddenAttributesError

class Api::V1::RegistrationsController  < ApplicationController

  skip_before_filter :verify_authenticity_token
  respond_to :json

  def create

    user = User.new(params[:user])

    if user.save
      render :json => user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
      return
    else
      warden.custom_failure!
      render :json => user.errors, :status=>422
    end
  end

  def user_params
    params.require(:user).permit(:email, :password)
  end

end
Run Code Online (Sandbox Code Playgroud)

这是我的JSON请求:

 Processing by Api::V1::RegistrationsController#create as JSON
 Parameters: {"user"=>{"email"=>"jayson@jayson.com", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"jayson@jayson.com", "password"=>"[FILTERED]"}}}
Run Code Online (Sandbox Code Playgroud)

我意识到这与强参数有关,但还没有破解它.

devise strong-parameters ruby-on-rails-4

13
推荐指数
1
解决办法
8182
查看次数

ice_cube和recurring_select宝石和事件

我正在尝试利用ice_cube和recurring_select宝石的[超棒]功能来处理重复发生的事件.我的schedule数据库中有一个(文本)列,事件模型中有以下内容:

  def schedule=(new_schedule)
    write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_yaml)
  end

  def converted_schedule
     Schedule.from_yaml(self.schedule, :start_date_override => self.start_date)
  end 
Run Code Online (Sandbox Code Playgroud)

查看psql中的schedule列,它似乎正确地存储了日程表.

这是我的表格:

.control-group
  = f.label 'Date', :class => 'control-label'
  .controls
    = f.text_field :start_date, :class => 'datepicker'

.control-group
  = f.label 'Recurring?', :class => 'control-label'
  .controls
    = f.select_recurring :schedule, :allow_blank => true
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试输出时converted_schedule,它只显示开始日期,不会显示任何其他日期.我有一些怀疑,我没有成功,但是YAML没有正确地转换为converted_schedule方法?也许我需要一个结束日期(我没有看到recurring_select上这个功能可用的地方)?

ruby-on-rails ice-cube

8
推荐指数
1
解决办法
2207
查看次数

Mandrill API模板

我正在使用Mandrill的Ruby API Gem并使用以下简单模板进行测试:

<html>

    <body>
        <h1 mc:edit="header">testastic</h1>
        <hr/>
        <br/><br/>
        <div mc:edit="main_section"></div>
        <hr/>
        <div mc:edit="footer"></div>
    </body>
 </html>
Run Code Online (Sandbox Code Playgroud)

按照Heroku指南中的示例,我有以下Ruby代码:

require 'mandrill'
  m = Mandrill::API.new
  rendered = m.templates.render 'test-template', [{:header => 'some header text', :main_section => 'The main content block', :footer => '<h3>asdf</h3>'}]

  mail(:to => "Jayson Lane <jayson@domain.com>", :subject => "Test Email") do |format|
       format.html { rendered['html'] }
       #format.text { render "test" }
  end
Run Code Online (Sandbox Code Playgroud)

这很好用,电子邮件发送我的模板很好,但是,它不会取代模板mc:edit变量.我错过了什么吗?

ruby email ruby-on-rails heroku mandrill

5
推荐指数
1
解决办法
3536
查看次数

使用to_json包含方法的嵌套信息

我有一个嵌套的方法,我想通过to_json输出:

Venue有一个调用的方法published_events返回发布的事件:

def published_events

    events_array = []

    self.events.each do |event|
      if event.published
        events_array << event
      end
    end

    events_array

  end
Run Code Online (Sandbox Code Playgroud)

Event我有一个to_param方法,我想在json渲染中包含Venue:

format.json { render :json => @venue.to_json(:methods => :published_events => {:include => :to_param}) }
Run Code Online (Sandbox Code Playgroud)

当然,这不包括to_param事件方法.我还有其他方法可以解决这个问题,还是需要建立自己的json?published_events我可以在方法中包含to_param方法吗?

json ruby-on-rails

5
推荐指数
1
解决办法
2831
查看次数

存储在lib(heroku)中的生成未初始化的常量自定义类

我有一个存储在/ lib(/lib/buffer_app.rb)中的自定义类:

require 'HTTParty'

class BufferApp
  include HTTParty
  base_uri 'https://api.bufferapp.com/1'

  def initialize(token, id)
    @token = token
    @id = id
  end

  def create(text)
    message_hash = {"text" => text, "profile_ids[]" => @id, "access_token" => @token}

    response = BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
  end
end
Run Code Online (Sandbox Code Playgroud)

我试图在Active Admin资源中使用此类,并在生产(Heroku)时收到以下错误:

NameError (uninitialized constant Admin::EventsController::BufferApp):
Run Code Online (Sandbox Code Playgroud)

值得注意的是,我在application.rb中有这一行,并且此功能在开发中本地工作:

config.autoload_paths += %W(#{Rails.root}/lib)
Run Code Online (Sandbox Code Playgroud)

如果我尝试include BufferApprequire 'BufferApp'该行本身导致错误.我有命名空间问题吗?这需要是一个模块吗?或者这是一个简单的配置疏忽?

namespaces ruby-on-rails class heroku

5
推荐指数
3
解决办法
1797
查看次数