ios - 如何从设备连接到 Stripe 服务器?
问题描述
我正在使用 Stripe 和启用了 sinatra 和 json 的 ruby 脚本在 iOS 上对信用卡收费。收费适用于 iPhone 6 模拟器,但不适用于运行 9.3.5 的 iPad mini 设备。
我尝试将 baseURL 字符串更改为我的 ip 地址,以便应用程序可以连接到服务器htpp://192.168.1.11
,但仍然出现错误。我什至尝试过类似的东西http://192.168.1.11:4567
。如何让物理应用程序连接到服务器?
//original baseURL for the app
enum Constants {
...
static let baseURLString = "http://localhost:4567"
...
}
iPhone 6 模拟器
iPad mini 9.3.5 版
原始教程使用 Swift 4、iOS 11、Xcode 9,但我将部署目标和 podfile 更改为 iOS9。
platform :ios, '9.0'
target 'RWPuppies' do
use_frameworks!
pod 'Alamofire', '~> 4.5'
pod 'AlamofireImage', '~> 3.3'
pod 'Stripe'
pod 'Cards'
end
红宝石脚本
#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
解决了:
打开我的 Projects info.plist 文件并添加了一个名为 NSAppTransportSecurity 作为字典的密钥。添加了一个名为 NSAllowsArbitraryLoads 的子项作为布尔值并将其值设置为 YES 如何在 iOS 9 中启用 App Transport Security 的情况下加载 HTTP URL?
将 baseURLString 设置为
http://192.168.1.11:4567
从终端运行脚本
ruby web.rb -o 0.0.0.0
无法从同一网络上的另一台计算机访问本地 Sinatra 服务器
解决方案
推荐阅读
- python - 如果我有两个 for 循环,一个循环一个常数值,另一个循环遍历数组大小 M,时间复杂度是 O(M) 还是 O(kM)?
- scala - Liquibase - 如何使用 play-slick 在 play 框架中为第二个数据库添加更改日志
- java - 无法在“/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/jarsigner”中找到可执行文件
- javascript - 为什么我的 CSS 样式没有应用于笔记本电脑媒体查询?
- spring - 哪个版本的eclipse支持STS插件?
- protocol-buffers - clang-format 在 proto 文件中返回后删除缩进
- .htaccess - 想要使用随机字符串访问图像,路径将是 htaccess 中的图像名称
- flutter - 试图在颤动中建立一个具有发光效果的圆形
- python - Stripe API,如何从 django 的 ListView 定义中获取“subscription.status”
- jquery - 如何在 devextreme 中使用 ajax 发送选定的数据网格对象