I'm using Stripe and a sinatra and json enabled ruby script to charge credit cards on iOS. The charge works on the iPhone 6 simulator but not an iPad mini device running 9.3.5.
I tried changing the baseURL string to my ip address so the app can connect to the server htpp://192.168.1.11
but it still gets the error. I even tried something like http://192.168.1.11:4567
. How can I get the physical app to connect to the server?
//original baseURL for the app
enum Constants {
...
static let baseURLString = "http://localhost:4567"
...
}
iPhone 6 Simulator
iPad mini version 9.3.5
The original tutorial used Swift 4, iOS 11, Xcode 9 but I changed the deployment target and podfile to iOS9.
platform :ios, '9.0'
target 'RWPuppies' do
use_frameworks!
pod 'Alamofire', '~> 4.5'
pod 'AlamofireImage', '~> 3.3'
pod 'Stripe'
pod 'Cards'
end
Ruby script
#1
require 'sinatra'
require 'stripe'
require 'json'
#2
Stripe.api_key = 'YOUR_TEST_SECRET_KEY'
#3
get '/' do
status 200
return "RWPuppies back end has been set up correctly"
end
#4
post '/charge' do
#5
payload = params
if request.content_type.include? 'application/json' and params.empty?
payload = indifferent_params(JSON.parse(request.body.read))
end
begin
#6
charge = Stripe::Charge.create(
:amount => payload[:amount],
:currency => payload[:currency],
:source => payload[:token],
:description => payload[:description]
)
#7
rescue Stripe::StripeError => e
status 402
return "Error creating charge: #{e.message}"
end
#8
status 200
return "Charge successfully created"
end
Solved:
Opened my Projects info.plist file and Added a Key called NSAppTransportSecurity as a Dictionary. Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES How do I load an HTTP URL with App Transport Security enabled in iOS 9?
set baseURLString to
http://192.168.1.11:4567
Ran the script from the terminal as
ruby web.rb -o 0.0.0.0
Cannot access local Sinatra server from another computer on same network