2

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

enter image description here

iPad mini version 9.3.5

enter image description here

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:

  1. 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?

  2. set baseURLString to http://192.168.1.11:4567

  3. 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

Aaron Navies
  • 1,213
  • 1
  • 11
  • 16
  • 2
    Are you missing https://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – Sachin Vas Mar 10 '19 at 05:31
  • Thanks for your answer, I added the plsit update to allow arbitrary loads and added my ip address to the base URL and now the app gets an unsupported URL error. When i keep the original `http://localhost:4567` I get the same could not connect to server error. – Aaron Navies Mar 10 '19 at 06:00
  • 1
    Solved: This helped. Thank you – Aaron Navies Mar 10 '19 at 07:45

0 Answers0