Cannot import Firebase in CocoaPod - swift

I'm creating a CocoaPod from which I'd like to import Firebase. I get the error:
"No such module 'Firebase'"
When I add import Firebase to a Swift file in my pod.
My CocoaPod Foo's pod spec file, Foo.podspec, contains:
s.dependency 'Firebase', '~> 3.6'

It seems there is a problem with the module mapping in the podspec made by Firebase for the latest version of their pod (see https://github.com/CocoaPods/CocoaPods/issues/6138).
I am currently working on a chat system based on Firebase that I have abstracted as a private CocoaPod. If I erase all traces of Firebase in my code/ podspec, all other Pods are imported flawlessly. I don't know that there is much we can do until this is fixed.
Cheers!

I recently ran into this same problem and the solution I settled on so that I could use firebase from inside both my development pod as well as apps using it was to setup the firebase sdk inside Xcode so that it can be found in the same way that a system framework is.
Download the firebase sdk
Move the frameworks you need into Xcode /Applications/Xcode.app/Contents/Developer/Library/Frameworks/
Setup your pod spec so that it knows where the frameworks are as well as add a few required dependencies.
# Specify what libraries this depends on.
s.libraries = [
'c++', # FirebaseAnalytics.
'icucore', # FirebaseDatabase.
'sqlite3', # FirebaseAnalytics.
'z', # FirebaseAnalytics.
]
# Specify what frameworks this depends on.
s.frameworks = [
'AddressBook', # FirebaseAnalytics.
'AdSupport', # FirebaseAnalytics.
'CFNetwork', # FirebaseDatabase.
'SafariServices', # FirebaseAnalytics.
'Security', # FirebaseAnalytics, FirebaseAuth, FirebaseDatabase.
'StoreKit', # FirebaseAnalytics.
'SystemConfiguration', # FirebaseAnalytics, FirebaseDatabase.
'FirebaseAnalytics',
'FirebaseInstanceID',
'FirebaseCore',
'FirebaseCoreDiagnostics',
'FirebaseNanoPB',
'GoogleToolboxForMac',
'FirebaseAuth',
'GTMSessionFetcher',
'FirebaseDatabase'
]
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/**' }
# LDFLAGS required by Firebase dependencies.
s.pod_target_xcconfig = {
'OTHER_LDFLAGS' => '$(inherited) -ObjC',
}
This example only uses firebase Analytics, Auth and Database but I'm sure other frameworks could be added as well. It isn't the best solution but it works for my situation.

Related

Unable to Determine Swift Version for the Following Pods Error

I am trying to use Algolia for iOS. SWIFT_VERSION is not found for the Pod and throwing an error
Disclaimer, Algolia put out a podsec that does include the SWIFT_VERSION so I am able to proceed forward but wanted to know for the future if I run into the following error again
For the old pod, I followed the instructions here
https://cocoapods.org/pods/InstantSearchClient
I received this error
Unable to determine swift version for the following pods:
‘InstantSearchClient-library’ does not specify a Swift version and none of the
targets ( ‘Pods’ ) integrating it have the ‘SWIFT_VERSION’ attribute set. Please
contact the author or set the ‘SWIFT_VERSION’ attribute in at least one of the targets that inegrate this pod
StackOverflow had the following suggestions which did not work for me
use a pre_install
error: SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2. (in target 'Starscream')
set the ENV['SWIFT_VERSION'] = '5' at the top of the Podfile
'Unable to determine Swift version for the following pod" - Error
Set the SWIFT_VERSION in code ( I received an error message that the variable SWIFT_VERSION ) was already in use
Here is my code:
ENV['SWIFT_VERSION'] = '5'
platform :ios, '9.0'
pod 'InstantSearchClient', '~> 7.0'
target 'contacts' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
project 'contacts'
# Pods for contacts
target 'contactsTests' do
inherit! :search_paths
# Pods for testing
end
target 'contactsUITests' do
# Pods for testing
end
pre_install do |installer|
installer.analysis_result.specifications.each do |s|
if s.name == 'InstantSearchClient'
s.swift_version = '5.0'
end
end
end
end

Unable to access toBlocking() in xctest

I am trying to write test cases and trying to access a method which returns Single object. For this I want to use toBlocking but I am not able to access it and getting following error:
Value of type 'Single<[Property]>' (aka
'PrimitiveSequence>') has no member
'toBlocking'
Following is my code
do {
let property = try viewModel.getPropertyList(city: "1530")
.toBlocking()
.single()
XCTAssertNotNil(property)
} catch {
XCTFail("Get user settings failed")
}
Already imported following frameworks:
import RxCocoa
import RxSwift
import XCTest
You need to import RxBlocking too!
if it raises error then you should add RxBlocking to your Test target in your package manager.
For example in Pod you should have something like this in your Pod file :
target 'YourProjectTests' do
pod 'RxSwift', '~> 4.0'
pod 'RxCocoa', '~> 4.0'
pod 'RxBlocking', '~> 4.0'
pod 'RxTest', '~> 4.0'
end

Couldn't load the Unicode tables for UTF8Handler in Rails Admin (1.2.0)

I want to upgrade rails 3 to rails 5. There I am using mongodb as database. I am using rails admin 1.2.0. I am using jruby-9.1.7.0. I am rails api only app. My application gems are given below.
gem 'rails', '~> 5.1.4'
gem 'awesome_print', '~> 1.8.0'
gem 'devise', github: 'plataformatec/devise', :branch => 'master', :ref => "463351922fdafb96c50ba2496c7d0adaa3223283"
gem "doorkeeper-mongodb", github: "doorkeeper-gem/doorkeeper-mongodb"
gem 'cancan', github: 'DevAVIJIT7/cancan', :branch => 'master', :ref => "aa3729bd79d92a993c5186f983eccd2fd496c2d3"
gem 'puma','~> 3.11.0'
gem 'mongoid', '6.2.1'
gem 'mongoid-tree', '~> 2.1.0'
gem 'rails_admin', '~> 1.2'
In my routes rails admin mount path and initializer file look like
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
RailsAdmin.config do |config|
RAILS_ADMIN_BASE_PATH = 'godview'
config.main_app_name = Proc.new do |controller|
[ "Admin", "#{controller.params[:action].try(:titleize)}" ]
end
config.authenticate_with do
authenticate_or_request_with_http_basic('Login required') do |username, password|
user = User.where(username: username).first
if user && user.valid_password?(password) && user.role_names.include?("Super Admin")
user
else
nil
end
end
end
end
when I run http://localhost:3000/admin on browser I am getting error.
In console I am getting
Started GET "/godview" for 0:0:0:0:0:0:0:1 at 2018-01-15 14:54:12
+0530
Processing by RailsAdmin::MainController#dashboard as HTML
Completed 401 Unauthorized in 263ms
IOError (Couldn't load the Unicode tables for UTF8Handler (undefined method
`call' for nil:NilClass
Did you mean? caller), ActiveSupport::Multibyte is unusable):
I went through the link Rails: Couldn't load the Unicode tables for UTF8Handler But didn't get any response.
*note : I am using /admin as /godview in my app.
Thanks
We are using Docker on CentOS for our rails projects, and we got this error recently, we fixed it by explicitly specifying the C.UTF8 encoding in the docker file as below:
ENV LANG C.UTF-8
Encoding
By default, Ruby inherits the locale of the environment in which it is run. For most users running Ruby on their desktop systems, that means it's likely using some variation of *.UTF-8 (en_US.UTF-8, etc). In Docker, however, the default locale is C, which can have unexpected results. If your application needs to interact with UTF-8, it is recommended that you explicitly adjust the locale of your image/container via -e LANG=C.UTF-8 or ENV LANG C.UTF-8
References:
https://hub.docker.com/_/ruby/
https://oncletom.io/2015/docker-encoding/

uninitialized constant Mongoid::Slug

this is my first development on rails, so Im still learning. I'm having a problem with mongoid_slug. In my local development mongoid_slug works fine, but when I test it on production I'm having this error:
uninitialized constant Mongoid::Slug
This is my full trace: http://pastebin.com/7x0q5VwY
If I try to save the document error appears.
This is my GemFile:
gem 'rails', '4.0.0'
gem 'mongoid', '~> 4.0.0.beta1', github: 'mongoid/mongoid'
gem 'bson_ext'
gem 'cancan'
gem 'ckeditor'
gem 'mongoid_slug', '3.2'
gem 'sass-rails', '~> 4.0.0'
gem 'bootstrap-sass', '~> 3.1.1'
This is my model:
class Noticium
include Mongoid::Document
include Mongoid::Slug
field :titulo, type: String
slug :titulo, history: true
field :contenido, type: String
field :imagen, type: String
field :imagen_url, type: String
field :tipo, type: String
field :fecha_registro, type: DateTime
validates :titulo, uniqueness: true
validates :titulo, :contenido, :imagen_url, :tipo, presence: true
end
This is part of my controller where the error appears:
private
def set_noticium
#noticium = Noticium.find(params[:id])
end
def noticium_params
params.require(:noticium).permit(:titulo, :contenido, :imagen, :tipo,
:fecha_registro)
end
I have read related info but I can't figure out what could be wrong.
My website is hosted on Digital Ocean, I have checked the version of Rails, Ruby and mongodb they are the same that in my local machine.
Could someone help me to figure whats going on? Why on my local development the slug field is working and on production im having errors.
Thanks in advance.
Maybe the MongoID version?
http://rubygems.org/gems/mongoid_slug
Runtime Dependencies
mongoid > 3.0
And you are using Mongoid 4.0
Update: see this issue on Github: https://github.com/digitalplaywright/mongoid-slug/issues/30
My bad. Have to release master, which works without requiring the
path, to RubyGems.

Config CarrierWave with Mongoid - GridFS

I am getting a trouble, trying to use CarrierWave for a file upload Rest API developed in Rails 3, with a MongoDB database.
What I would like to do is storing some files (not only images but every file format) with the MongoDB system GridFS.
I read many documentations that recommend my to use the CarrierWave gem.
But I have an error when I try to configure it.
My development environment :
The Gemfile :
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# MongoDB
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
gem 'carrierwave', :git => "git://github.com/jnicklas/carrierwave.git"
# gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mini_magick', :git => 'git://github.com/probablycorey/mini_magick.git'
gem 'bson_ext'
gem 'json'
The application.rb :
require File.expand_path('../boot', __FILE__)
# ActiveRecord will not be use with MongoDB
# require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
require "mongoid/railtie"
require "carrierwave"
# require "carrierwave/mongoid"
I define the database with a mongoid.yml (config/mongoid.yml) file :
development:
sessions:
default:
database: lf_rest_api_development
hosts:
- localhost:27017
options:
consistency: :strong
options:
test:
sessions:
default:
database: lf_rest_api_test
hosts:
- localhost:27017
options:
consistency: :strong
And load it with an initializer (config/initializers/mongoid.rb) :
Mongoid.load!("config/mongoid.yml")
-- I can execute the "rails server" command without problems after the last file, config/initializers/carrierwave.rb :
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid.database.name
config.grid_fs_host = Mongoid.config.master.connection.host
config.storage = :grid_fs
config.grid_fs_access_url = "/files"
end
And then get the following error when I run the "rails server" command :
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/{API_path}/config/initializers/zcarrierwave.rb:4:in `block in <top (required)>': undefined method `database' for Mongoid:Module (NoMethodError)
[...]
My file model is defined as following :
require 'carrierwave/orm/mongoid'
class File
include Mongoid::Document
store_in_collection: "files", database: "lf_rest_api_developement", session: "default"
key :filename, type: String
key :content_type, type: String
key :length, type: BigDecimal
key :chunk_size, type: Integer, :default => 256
key :upload_date, type: DateTime
key :md5, type: String
key :metadata, type: Array, :default => []
mount_uploader :file, FileUploader
index({ location: "2d" }, { min: -200, max: 200 })
end
The FileUploader is just an extension of CarrierWave uploader...
class FileUploader < CarrierWave::Uploader::Base
storage :grid_fs
end
Sorry about the slow response. Firstly, the reason for your error is that Mongoid 3 no longer supports Mongoid.database. You can now find these configurations in the Mongoid::Config.sessions[:default] object.
BUT THIS AIN'T GONNA FIX YOUR PROBLEM! Mongoid 3 has no GridFS support at all. From mongoid docs:
No GridFS Support
GridFS is marketed as a core database feature, when in fact it is not. It is simply a pattern for storing chunked file data as documents in a collection, just like any other document. The implementation of this behaviour is handled in the client drivers, not in the core database itself, which can lead to discrepencies in how this is handled across > platforms.
Even if having this behaviour in the client is acceptable, the effects of this on application performance where you are not just storing file data is quite large. Since files are stored as documents, they consume RAM just as any other document in the database would, and can easily cause memory consumption on your server to max out. There are also limitations in chunking the data, such as you do not have the ability to update a file - you must delete the file and replace it with a new one.
Given this, we did not prioritize any work with GridFS at the front, but there is a gem in the pipeline for those who can wait a bit to upgrade. In the meantime you have a few options...
So rather than seek other ways to store uploads in the GridFS at the expense of performance, I would suggest just throwing them in a SQL database. If your using Mongo as your only database, don't be put off by this option. It's not very difficult to get ActiveRecord and Mongoid working together side-by-side. But from my experience, uploading binary objects to any database may not perform well. I would personally use a filesystem for storage, with carrierwave or paperclip taking care of the management. Alternatively, I would suggest checking out some cheap cloud storage options. You can use something like aws-s3, a great service. It also has very well documented compatibility with Carrierwave.
If you are determined to use GridFS, I would check out the mongoid-grid_fs gem or check out some alternative ruby MongoDB drivers on the 10gen website.
This is my first time answering a question so I hope I'm doing this right.
I was struggling with the same issue uploading an image using carrier wave in my rails application with Mongoid 3. I believe I have a solution (at least got it working locally on my laptop.) Here is what I came up with:
Add carrierwave-mongoid gem to your gemfile with the branch mongoid-3.0. This gem uses mongoid-grid_fs:
# Image Uploading
gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0"
Make an initializer for carrier wave:
#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :grid_fs
# Storage access url
config.grid_fs_access_url = "/upload/grid"
end
I know I didn't set config.grid_fs_database or config.grid_fs_host. This seems to work locally (on my laptop) I haven't tried it with a remote gridfs database.
Mounting looks normal:
#app/models/user.rb
class User
include Mongoid::Document
mount_uploader :avatar, AvatarUploader
end
Uploader is also standard:
#app/uploaders/avatar_uploader
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def store_dir
"#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [200, 200]
end
end
Create a controller for GridFS:
#app/controllers/gridfs_controller.rb
class GridfsController < ApplicationController
def serve
gridfs_path = env["PATH_INFO"].gsub("/upload/grid/", "")
begin
gridfs_file = Mongoid::GridFS[gridfs_path]
self.response_body = gridfs_file.data
self.content_type = gridfs_file.content_type
rescue
self.status = :file_not_found
self.content_type = 'text/plain'
self.response_body = ''
end
end
end
and add the route to the routes file:
#config/routes.rb
match "/upload/grid/*path" => "gridfs#serve"
Hope this helps.