Skip to content

Instantly share code, notes, and snippets.

@joenoon
Last active October 14, 2020 20:21
Show Gist options
  • Save joenoon/4156512 to your computer and use it in GitHub Desktop.
Save joenoon/4156512 to your computer and use it in GitHub Desktop.
RubyMotion - read entitlements from the provisioning_profile
# read entitlements from the provisioning_profile
# you can the set it like this:
# app.entitlements = app.read_provisioning_profile_entitlements
module Motion
module Project
class Config
def read_provisioning_profile_entitlements
text = File.read(provisioning_profile)
text.force_encoding('binary') if RUBY_VERSION >= '1.9.0'
text = text.scan(/<key>\s*Entitlements\s*<\/key>\s*<dict>(.*?)\s*<\/dict>/m)[0][0]
output = {}
current_key = nil
text.scan(/(<(array|string|key)>(.*?)<\/(\2)>|<(true)\/>|<(false)\/>)/m).each do |x|
type = (x[1] || x[4] || x[5]).to_s.strip
val = if type == "true"
true
elsif type == "false"
false
elsif type == "array"
x[2].to_s.scan(/<string>(.*?)<\/string>/).map { |str| str[0].strip }
else
x[2].to_s.strip
end
if type == "key"
current_key = val
else
output[current_key] = val
end
end
output
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment