forked from Unity-Technologies/unity-ads-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_webview_plist.rb
executable file
·64 lines (53 loc) · 1.43 KB
/
set_webview_plist.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'bundler'
Bundler.require(:default)
INFO_PLIST_PATH = 'UnityAdsExample/Info.plist'
INFO_PLIST_WEBVIEW_KEY = 'UADSWebviewBranch'
class InfoPlist
def initialize(file_path)
@info_plist_path = file_path
begin
@info_plist_hash = Plist::parse_xml(file_path)
rescue Exception => e
puts "Cannot read plist from file '#{file_path}': #{e}"
raise e
end
end
def set_webview(webview_string)
begin
@info_plist_hash[INFO_PLIST_WEBVIEW_KEY] = webview_string
rescue Exception => e
puts "Unable to add webview '#{webview_string}' to key '#{INFO_PLIST_WEBVIEW_KEY}' in plist: #{e}"
raise e
end
end
def clear_webview
@info_plist_hash[INFO_PLIST_WEBVIEW_KEY] && @info_plist_hash.delete(INFO_PLIST_WEBVIEW_KEY)
end
def list_current
puts "#{@info_plist_hash[INFO_PLIST_WEBVIEW_KEY]}"
end
def to_file
begin
File.open(@info_plist_path, 'wb') do |fh|
fh.write(@info_plist_hash.to_plist)
end
rescue Exception => e
puts "Cannot write plist to file '#{@info_plist_path}': #{e}"
raise e
end
end
end
# Handle command line arguments
opts = Optimist::options do
opt :webview, "Webview that ads sdk will use in the build",
:type => :string
end
webview = opts[:webview]
if !opts[:webview]
Optimist::die "Webview not given, exiting"
exit
end
ip = InfoPlist.new(INFO_PLIST_PATH)
ip.clear_webview
ip.set_webview(webview)
ip.to_file