小编ale*_*our的帖子

AFNetworking + cancelAllRequests

当我想在使用AFNetworking构建的同步引擎中停止所有当前请求时,我确实遇到了问题.

我有5个不同的URL来查询.如果前一个查询正确执行,则每个查询都会启动

这非常有效.

我想随时停止同步过程.所以我的代码是:

- (void)cancelAllRequests
{
  NSLog(@"CancelAllRequests");

  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull_items"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull_image"];
  [[HTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"POST" path:@"ws/webapp/services/push_item"];  
  [[[HTTPClient sharedClient] operationQueue] cancelAllOperations];
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码似乎无能为力.当我想取消时,我在调用方法后看到所有批处理操作在我的日志中工作.

我错过了什么 ?如果我取消请求,这不会停止使用此请求构建的所有活动操作吗?

afnetworking

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

将半透明效果移除到MFMailComposeViewController的UINavigationBar

我没有找到将半透明效果(iOS 7)移除到MFMailComposeViewController的UINavigationBar的方法.我的应用程序中的所有其他UINavigationBars没问题.

我尝试了这个没有成功:

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)

任何的想法 ?

translucency ios7

12
推荐指数
1
解决办法
1539
查看次数

Rails 3,导入前检查CSV文件编码

在我的应用程序(Rails 3.0.5,Ruby 1.8.7)中,我创建了一个导入工具来从文件导入CSV数据.

问题:我要求我的用户以UTF-8编码从Excel导出CSV文件,但他们大部分时间都不会这样做.

如何在导入前验证文件是否为UTF-8?否则导入将运行,但会产生奇怪的结果.我使用FasterCSV导入.

错误的CSV文件的例子:

;VallÈe du RhÙne;CÙte Rotie;
Run Code Online (Sandbox Code Playgroud)

谢谢.

ruby csv ruby-on-rails

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

Ruby获取数组的字节大小

我想获得ruby中数组(项)内容的大小(以字节为单位).

我这样填充我的数组:

  @records.each do |record|
    items << { :table => table, :id => record.id, :lruos => record.updated_at }
  end
Run Code Online (Sandbox Code Playgroud)

实际上,当我在JSON中序列化时,我想强制发送此数组的Content-Length:

respond_to do |format|
  #response['Content-Length'] = items.to_s.size
  format.json { render :json => { :success => "OK", :items => items } }
end
Run Code Online (Sandbox Code Playgroud)

因此,任何想法都可能很有趣.(因为我不知道内容长度没有发送,所以我想强迫它)

我使用Rails 3.0.5.

ruby arrays

10
推荐指数
2
解决办法
5778
查看次数

ElasticSearch with multi_match AND bool

我尝试学习Elasticsearch以将其添加到我的Rails应用程序中.我想在2个字段中执行multi_match查询(就好像它们只是一个字段一样),并且还有一个必须等​​于1的另一个字段(状态)的过滤器.

response = Wine.search({
            query: {
                multi_match: {
            query: "test",
            fields: ["winery", "name"]
            },
        bool: {
          must: {
            term: { status: 1 }
            },
          should: [],
          minimum_should_match: 1
        }
      }     
        })
Run Code Online (Sandbox Code Playgroud)

错误是:

"fields\":[\"winery\",\"name\"]},\"bool\":{\"must\":{\"term\":{\"status\":1}},\"should\":[],\"minimum_should_match\":1}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"bool\"]; }]","status":400}
Run Code Online (Sandbox Code Playgroud)

请求有什么问题?如何一起执行multi_match和BOOL?

elasticsearch

9
推荐指数
1
解决办法
7964
查看次数

AFNetworking 2.6是否与IPv6兼容?

我实际上不能使用AFNetworking 3.x. 2.6.X版本是否与IPv6兼容?甚至可达性?

Apple说:

从2016年6月1日开始,提交到App Store的所有应用都必须支持仅IPv6网络.大多数应用程序不需要任何更改,因为NSURLSession和CFNetwork API已经支持IPv6.

我没有使用NSURLSession而是使用NSURLConnection ...(等待我的应用程序在接下来的几个月内迁移到Swift以使用NSURLSession).

请注意,我在我的应用中使用带有名称的URL,而不是IP.

谢谢,

ipv6 afnetworking-2

9
推荐指数
0
解决办法
3823
查看次数

PostgreSQL,三元组和相似性

只是在我的Mac上测试PostgreSQL 9.6.2并使用Ngrams.假设酿酒厂有一个GIN三元组指数.

相似性的限制(我知道这已被弃用):

SELECT set_limit(0.5);
Run Code Online (Sandbox Code Playgroud)

我正在2,3M行表上构建一个trigram搜索.

我的选择代码:

SELECT winery, similarity(winery, 'chateau chevla blanc') AS similarity 
FROM usr_wines 
WHERE status=1 AND winery % 'chateau chevla blanc'  
ORDER BY similarity DESC;
Run Code Online (Sandbox Code Playgroud)

我的结果(在我的Mac上329毫秒):

Chateau ChevL Blanc 0,85
Chateau Blanc   0,736842
Chateau Blanc   0,736842
Chateau Blanc   0,736842
Chateau Blanc   0,736842
Chateau Blanc,  0,736842
Chateau Blanc   0,736842
Chateau Cheval Blanc    0,727273
Chateau Cheval Blanc    0,727273
Chateau Cheval Blanc    0,727273
Chateau Cheval Blanc (7)    0,666667
Chateau Cheval Blanc Cbo    0,64
Chateau Du Cheval Blanc 0,64
Chateau …
Run Code Online (Sandbox Code Playgroud)

postgresql similarity trigram

8
推荐指数
3
解决办法
2534
查看次数

Rails - 添加不在模型和更新模型属性中的属性

我的表格中有3个字段,不在我的数据库中:opening_type,opening_hours,opening_minutes.我想用这3个字段更新主要属性"打开"(在数据库中).

我尝试了很多不起作用的东西.

其实我有:

  attr_accessor :opening_type, :opening_hours, :opening_minutes

  def opening_type=(opening_type)
  end
  def opening_type
    opening_type = opening.split("-")[0] if !opening.blank?
  end

  def opening_hours=(opening_hours)
  end
  def opening_hours
    opening_hours = opening.split("-")[1] if !opening.blank?
  end  

  def opening_minutes=(opening_minutes)
  end
  def opening_minutes
    opening_minutes = opening.split("-")[2] if !opening.blank?    
  end
Run Code Online (Sandbox Code Playgroud)

我尝试添加类似的东西:

  def opening=(opening)
    logger.info "WRITE"

    if !opening_type.blank? and !opening_hours.blank? and opening_minutes.blank?
      opening = ""
      opening << opening_type if !opening_type.blank?
      opening << "-" 
      opening << opening_hours if !opening_hours.blank?
      opening << "-" 
      opening << opening_minutes if !opening_minutes.blank?
    end
    write_attribute(:opening, opening)
  end

  def …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails accessor

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

SQLite:获取当前周

我正在尝试获取当前周以在 SQLite 中进行日期比较。我上个月、去年、今天、昨天都没有问题……但没有找到当前周的解决方案。

我尝试了很多事情,例如:

SELECT tastings.* FROM tastings   
WHERE (DATE(tastings.date) > DATE('now','weekday 1','+ 7 days'))
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗 ?谢谢。

sqlite date

6
推荐指数
2
解决办法
8720
查看次数

AFNetworking +大下载文件+简历下载

我需要使用AFNetworking下载文件> 500 Mo. 有时,下载它们的时间大于10分钟,如果应用程序处于后台,则下载无法完成.

所以我想尝试部分下载.我找到了很多链接,这似乎可以在AFHTTPRequestOperation上使用pause()和resume()方法.

实际上,我做了:

  [self.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{   
    // Clean up anything that needs to be handled if the request times out
    [self.downloadOperation pauseDownload];
  }];
Run Code Online (Sandbox Code Playgroud)

DownloadOperation是AFHTTPRequestOperation(singleton)的子类.

在AppDelegate中:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  // resume will only resume if it's paused...
  [[DownloadHTTPRequestOperation sharedOperation] resumeDownload];  
}
Run Code Online (Sandbox Code Playgroud)

服务器可以在标题中获取新范围...

我的问题:

1)是不是这样做的好方法?2)简历是否需要更改outputStream(追加:NO =>追加:是)?或者它是由AFNetworking管理的吗?(找不到)

self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
Run Code Online (Sandbox Code Playgroud)

像这样的东西(在DownloadHTTPRequestOperation中):

- (void)pauseDownload
{
  NSLog(@"pause download");
  [self pause];
}

- (void)resumeDownload
{
  NSLog(@"resume download");
  self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
  [self resume];
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

resume download afnetworking

6
推荐指数
2
解决办法
7703
查看次数