Skip to content

Commit

Permalink
fix: can not register iOS device to apple developer (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed Sep 23, 2024
1 parent 6507593 commit 4d9bf3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/controllers/udid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def register
name = [ 'Zealot', platform, SecureRandom.hex(4) ].compact.join('-') if name.blank? # Max 50 chars

new_device = apple_key.register_device(udid, name, platform)
unless new_device.valid?
logger.debug "Register failed with errors: #{new_device.errors}"
error_message = new_device.errors.messages[:devices][0]
flash[:alter] = error_message if error_message.present?
if new_device.errors.present?
logger.debug "Register failed with errors: #{new_device.errors.full_messages}"
error_message = new_device.errors.messages[:name].join(' / ')
flash[:warn] = error_message if error_message.present?
return render :show, status: :unprocessable_entity
end

Expand Down
20 changes: 11 additions & 9 deletions app/models/apple_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def sync_devices
end

def register_device(udid, name = nil, platform = 'IOS')
remote_device = client.device(uuid: uuid)
remote_device = client.device(udid: udid)
db_device = Device.find_by(udid: udid)
return db_device if remote_device && db_device

if remtoe_device && !db_device
if remote_device && !db_device
devices << remote_device
return remote_device
end
Expand All @@ -62,33 +62,35 @@ def register_device(udid, name = nil, platform = 'IOS')
message = e.errors[0]['detail']
is_exists = message.include?('already exists')

# udid had registered, force sync device
# udid had registered, but not exists in zealot system, needs to force sync device
if is_exists
sync_devices
return self
end

invaild_device = Device.new
# invaild udid
if message.include?('invalid value')
# This is never happen, never ever!
errors.add(:devices, :invalid_value, value: udid)
invaild_device.errors.add(:name, :invalid_value, value: udid)
else
errors.add(:devices, :api, message: message)
invaild_device.errors.add(:name, :api, message: message)
end

self
invaild_device
rescue => e
logger.error "Register device raise an exception: #{e}"
logger.error e.backtrace.join("\n")

message = e.respond_to?(:errors) ? errors[0]['detail'] : e.message
errors.add(:devices, :unknown, message: message)

self
invaild_device = Device.new
invaild_device.errors.add(:name, :unknown, message: message)
invaild_device
end

def update_device_name(device)
response_device = client.rename_device(device.name, id: device.device_id, udid: device.udid)
client.rename_device(device.name, id: device.device_id, udid: device.udid)
rescue TinyAppstoreConnect::InvalidEntityError => e
logger.error "Device may not exists or the other error in apple key #{id}: #{e}"
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/udid/_register_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
.card-tools
.card-body
= f.error_notification
- unless f.object.errors.empty?
= debug f.object.errors
= f.input :name
= f.input :udid, as: :hidden, input_html: { value: udid }
= f.input :platform, as: :hidden, input_html: { value: product }
Expand Down
6 changes: 6 additions & 0 deletions config/locales/zealot/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ en:
invalid_value: Register device %{value} was invalid.
api: 'Apple return error: %{message}'
unknown: 'Unknown error: %{message}'
udid:
attributes:
name:
invalid_value: Register device %{value} was invalid.
api: 'Apple return error: %{message}'
unknown: 'Unknown error: %{message}'
debug_file:
attributes:
app_id:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/zealot/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ zh-CN:
invalid_value: 注册设备 %{value} 是无效的请检测后重新尝试
api: '苹果返回错误:%{message}'
unknown: '未知错误: %{message}'
udid:
attributes:
name:
invalid_value: 注册设备 %{value} 是无效的请检测后重新尝试
api: '苹果返回错误:%{message}'
unknown: '未知错误: %{message}'
debug_file:
attributes:
app_id:
Expand Down

0 comments on commit 4d9bf3d

Please sign in to comment.