Class: Pindo::BundleIdHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/module/appstore/bundleid_helper.rb

Overview

Bundle ID 管理辅助类负责在 Apple 开发者中心创建和配置 Bundle ID

Class Method Summary collapse

Class Method Details

.build_settings_for(settings_key:, options_key:) ⇒ Array

构建设置

Parameters:

  • settings_key (String)

    设置键

  • options_key (String)

    选项键

Returns:

  • (Array)

    设置数组



220
221
222
223
224
225
226
227
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 220

def self.build_settings_for(settings_key:, options_key:)
  [{
    key: settings_key,
    options: [{
      key: options_key
    }]
  }]
end

.create_bundleid(bundle_id:, app_group: nil, app_icloud: nil, setting_array: []) ⇒ Object

创建 Bundle ID

Parameters:

  • bundle_id (String)

    Bundle ID

  • app_group (Object) (defaults to: nil)

    App Group 对象

  • app_icloud (Object) (defaults to: nil)

    iCloud Container 对象

  • setting_array (Array) (defaults to: [])

    配置数组

Returns:

  • (Object)

    创建的 App 对象



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 98

def self.create_bundleid(bundle_id:, app_group: nil, app_icloud: nil, setting_array: [])
  return nil if bundle_id.nil?

  # 查找或创建 Bundle ID
  app = Spaceship::Portal.app.find(bundle_id)
  puts

  if app.nil?
    puts "Create bundle id #{bundle_id} in apple developer center..."
    app = Spaceship::Portal.app.create!(bundle_id: bundle_id, name: bundle_id.gsub('.', ''))
  else
    puts "Find bundle id #{bundle_id} in apple developer center..."
  end

  bundle_id_obj = Spaceship::ConnectAPI::BundleId.find(bundle_id)

  # 配置 Game Center
  if !bundle_id_obj.nil?
    if !setting_array.nil? && setting_array.to_s.include?("game_center")
      puts "Enable #{bundle_id} game_center on"
      bundle_id_obj.update_capability("GAME_CENTER", enabled: true)
    else
      puts "Enable #{bundle_id} game_center off"
      bundle_id_obj.update_capability("GAME_CENTER", enabled: false)
    end
  end

  return nil if setting_array.nil? || setting_array.length == 0

  # 配置 Push Notification
  if !app.nil? && setting_array.to_s.include?("push_notification")
    puts "Enable #{bundle_id} push on"
    app.update_service(Spaceship::Portal.app_service.push_notification.on)
  else
    app.update_service(Spaceship::Portal.app_service.push_notification.off)
    puts "Enable #{bundle_id} push off"
  end

  # 配置 Siri
  if !app.nil? && setting_array.to_s.include?("siri")
    puts "Enable #{bundle_id} siri on"
    app.update_service(Spaceship::Portal.app_service.siri_kit.on)
  else
    app.update_service(Spaceship::Portal.app_service.siri_kit.off)
    puts "Enable #{bundle_id} siri off"
  end

  # 配置 Sign with Apple
  if !bundle_id_obj.nil? && setting_array.to_s.include?("apple_signin")
    puts "Enable #{bundle_id} Sign with Apple on"
    settings = build_settings_for(settings_key: "APPLE_ID_AUTH_APP_CONSENT", options_key: "PRIMARY_APP_CONSENT")
    bundle_id_obj.update_capability("APPLE_ID_AUTH", enabled: true, settings: settings)
  else
    puts "Enable #{bundle_id} Sign with Apple off"
    bundle_id_obj.update_capability("APPLE_ID_AUTH", enabled: false)
  end

  # 配置 App Group
  if !app_group.nil? && setting_array.to_s.include?("app_group")
    puts "Enable #{bundle_id} group on"
    app.update_service(Spaceship::Portal.app_service.app_group.on)
    app.associate_groups([app_group])
  else
    puts "Enable #{bundle_id} group off"
    app.update_service(Spaceship::Portal.app_service.app_group.off)
  end

  # 配置 iCloud
  if !app_icloud.nil? && setting_array.to_s.include?("iclound")
    puts "Enable #{bundle_id} icloud on"
    app.update_service(Spaceship::Portal.app_service.cloud.on)
    app.update_service(Spaceship::Portal.app_service.cloud_kit.cloud_kit)
    app.associate_cloud_containers([app_icloud])
  else
    puts "Enable #{bundle_id} icloud off"
    app.update_service(Spaceship::Portal.app_service.cloud.off)
  end

  app
end

.create_extension_bundleids(app, app_group, app_icloud, config_info) ⇒ Object

创建扩展的 Bundle ID

Parameters:

  • app (Object)

    主应用对象

  • app_group (Object)

    App Group 对象

  • app_icloud (Object)

    iCloud Container 对象

  • config_info (Hash)

    配置信息



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 234

def self.create_extension_bundleids(app, app_group, app_icloud, config_info)
  return if app.nil?

  # Push Content Extension
  if !config_info[:bundle_id_pushcontent].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_pushcontent],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["push_notification"]
    )
  end

  # Push Service Extension
  if !config_info[:bundle_id_pushservice].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_pushservice],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["push_notification"]
    )
  end

  # Keyboard Extension
  if !config_info[:bundle_id_keyboard].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_keyboard],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group"]
    )
  end

  # iMessage Extension
  if !config_info[:bundle_id_imessage].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_imessage],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group"]
    )
  end

  # Siri Extension
  if !config_info[:bundle_id_siri].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_siri],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group", "siri"]
    )
  end

  # Siri UI Extension
  if !config_info[:bundle_id_siriui].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_siriui],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group", "siri"]
    )
  end

  # Widget Extension
  if !config_info[:bundle_id_widget].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_widget],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group"]
    )
  end

  # General Extension
  if !config_info[:bundle_id_extension].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_extension],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group"]
    )
  end

  # Ad Extension
  if !config_info[:bundle_id_extensionad].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_extensionad],
      app_group: app_group,
      app_icloud: app_icloud,
      setting_array: ["app_group"]
    )
  end

  # Watch App
  if !config_info[:bundle_id_watchapp].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_watchapp],
      app_group: nil,
      app_icloud: app_icloud,
      setting_array: ["push_notification"]
    )
  end

  # Watch App Extension
  if !config_info[:bundle_id_watchapp_extension].nil?
    create_bundleid(
      bundle_id: config_info[:bundle_id_watchapp_extension],
      app_group: nil,
      app_icloud: app_icloud,
      setting_array: ["push_notification"]
    )
  end
end

.create_group_id(group_id:) ⇒ Object

创建 App Group

Parameters:

  • group_id (String)

    Group ID

Returns:

  • (Object)

    App Group 对象



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 182

def self.create_group_id(group_id:)
  return nil if group_id.nil?

  app_group = Spaceship::Portal.app_group.find(group_id)

  if app_group.nil?
    puts "Create group_id #{group_id} in apple developer center..."
    app_group = Spaceship::Portal.app_group.create!(group_id: group_id, name: group_id.gsub('.', ''))
  else
    puts "Group_id #{group_id} is existed in apple developer center !!!"
  end

  app_group
end

.create_icloud_id(icloud_id:) ⇒ Object

创建 iCloud Container

Parameters:

  • icloud_id (String)

    iCloud ID

Returns:

  • (Object)

    iCloud Container 对象



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 200

def self.create_icloud_id(icloud_id:)
  return nil if icloud_id.nil?

  puts "icloud_id +++++ #{icloud_id}"
  app_icloud = Spaceship::Portal.cloud_container.find(icloud_id)

  if app_icloud.nil?
    puts "Create icloud_id #{icloud_id} in apple developer center..."
    app_icloud = Spaceship::Portal.cloud_container.create!(identifier: icloud_id, name: icloud_id.gsub('.', ''))
  else
    puts "icloud_id #{icloud_id} is existed in apple developer center !!!"
  end

  app_icloud
end

.execute_bundleid_creation(config_json:, sign_flag: false) ⇒ Object

执行 Bundle ID 创建流程

Parameters:

  • config_json (Hash)

    配置 JSON 对象

  • sign_flag (Boolean) (defaults to: false)

    签名标志



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 50

def self.execute_bundleid_creation(config_json:, sign_flag: false)
  # 提取配置信息
  config_info = extract_config_info(config_json)

  # 验证必需字段
  raise "配置文件中缺少 Apple ID" if config_info[:apple_id].nil? || config_info[:apple_id].empty?
  raise "配置文件中缺少 Bundle ID" if config_info[:bundle_id].nil? || config_info[:bundle_id].empty?

  # 登录 Apple 开发者中心
  puts config_info[:apple_id]
  puts "Login #{config_info[:apple_id]}..."
  Spaceship.(config_info[:apple_id].to_s)
  Spaceship.select_team

  # 创建 App Group
  app_group = nil
  if !config_info[:group_id].nil?
    app_group = create_group_id(group_id: config_info[:group_id])
  end

  # 配置参数
  parms = ["push_notification", "app_group"]

  # 创建 iCloud ID
  app_icloud = nil
  if !config_info[:icloud_id].nil?
    app_icloud = create_icloud_id(icloud_id: config_info[:icloud_id])
    parms << "iclound"
  end

  # 创建主应用 Bundle ID
  app = create_bundleid(
    bundle_id: config_info[:bundle_id],
    app_group: app_group,
    app_icloud: app_icloud,
    setting_array: parms
  )

  # 创建各种扩展的 Bundle ID
  create_extension_bundleids(app, app_group, app_icloud, config_info)
end

.extract_config_info(config_json) ⇒ Hash

从配置文件中提取所有必要的信息

Parameters:

  • config_json (Hash)

    配置 JSON 对象

Returns:

  • (Hash)

    提取的配置信息



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
# File 'lib/pindo/module/appstore/bundleid_helper.rb', line 12

def self.extract_config_info(config_json)
  config_info = {}

  # 提取 Apple ID
  if config_json['account_info'] && config_json['account_info']['apple_acount_id']
    config_info[:apple_id] = config_json['account_info']['apple_acount_id']
  end

  # 提取 Bundle ID 信息
  if config_json['app_info']
    app_info = config_json['app_info']
    config_info[:bundle_id] = app_info['app_identifier']
    config_info[:bundle_id_pushcontent] = app_info['app_identifier_pushcontent']
    config_info[:bundle_id_pushservice] = app_info['app_identifier_pushservice']
    config_info[:bundle_id_keyboard] = app_info['app_identifier_keyboard']
    config_info[:bundle_id_imessage] = app_info['app_identifier_imessage']
    config_info[:bundle_id_extension] = app_info['app_identifier_extension']
    config_info[:bundle_id_siri] = app_info['app_identifier_siri']
    config_info[:bundle_id_siriui] = app_info['app_identifier_siriui']
    config_info[:bundle_id_widget] = app_info['app_identifier_widget']
    config_info[:bundle_id_extensionad] = app_info['app_identifier_extensionad']
    config_info[:bundle_id_watchapp] = app_info['app_identifier_watchapp']
    config_info[:bundle_id_watchapp_extension] = app_info['app_identifier_watchapp_extension']
  end

  # 提取 App Group 和 iCloud ID
  if config_json['app_setting']
    app_setting = config_json['app_setting']
    config_info[:group_id] = app_setting['app_group_id']
    config_info[:icloud_id] = app_setting['app_icloud_id']
  end

  config_info
end