Class: GoNative::Plugins::IOS::SetBundleId

Inherits:
Object
  • Object
show all
Extended by:
DSL::Serviceable
Defined in:
lib/gonative/plugins/ios/set_bundle_id.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle_id, update_entitlements) ⇒ SetBundleId

Returns a new instance of SetBundleId.



14
15
16
17
# File 'lib/gonative/plugins/ios/set_bundle_id.rb', line 14

def initialize(bundle_id, update_entitlements)
  @bundle_id = bundle_id
  @update_entitlements = update_entitlements
end

Instance Attribute Details

#bundle_idObject (readonly)

Returns the value of attribute bundle_id.



12
13
14
# File 'lib/gonative/plugins/ios/set_bundle_id.rb', line 12

def bundle_id
  @bundle_id
end

Instance Method Details

#callObject



19
20
21
22
# File 'lib/gonative/plugins/ios/set_bundle_id.rb', line 19

def call
  update_project
  update_entitlements if update_entitlements?
end

#update_entitlementsObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/gonative/plugins/ios/set_bundle_id.rb', line 40

def update_entitlements
  entitlement_files = `find -E . -maxdepth 2 -regex ".*\.(entitlements)"`.split("\n")
  entitlement_files.each do |entitlement_file|
    plist = CFPropertyList::List.new(file: entitlement_file)
    entitlements = CFPropertyList.native_types(plist.value)
    entitlements['com.apple.security.application-groups'] = ["group.#{bundle_id}"]
    plist.value = CFPropertyList.guess(entitlements)
    plist.save(entitlement_file, CFPropertyList::List::FORMAT_XML)
  end
end

#update_projectObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gonative/plugins/ios/set_bundle_id.rb', line 24

def update_project
  proj = Xcodeproj::Project.open('./MedianIOS.xcodeproj')
  proj.targets.each do |target|
    case target.product_type
    when Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application]
      set_target_bundle_id(target, bundle_id)
    when Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension]
      set_target_bundle_id(target, "#{bundle_id}.#{target.name}")
    else
      next
    end
  end

  proj.save
end