matt matt - 1 year ago 73
iOS Question

With an iOS quick action (shortcut item), what is the purpose of the completion handler parameter?

An iOS quick action / shortcut item is received by the app delegate's implementation of


In that implementation, you are supposed to call the
. It takes a Bool.

Does anyone know what the Bool is for? I see no difference regardless of whether I pass
. (In fact, I see no difference even if I neglect to call the

Answer Source

Short answer: parameter is not used in implementation of block in iOS 10 (guess that in iOS 9 too, but can't check right now).

Long answer: let's see what happens inside of completion block:

___50-[UIApplication _handleApplicationShortcutAction:]_block_invoke:
push       rbp                               ; XREF=-[UIApplication _handleApplicationShortcutAction:]+132
mov        rbp, rsp
mov        rax, qword [ds:rdi+0x20]
mov        rdx, qword [ds:rdi+0x28]
mov        rsi, qword [ds:0x1179e88]         ; @selector(_updateSnapshotAndStateRestorationWithAction:)
mov        rdi, rax                          ; argument "instance" for method imp___got__objc_msgSend
pop        rbp
jmp        qword [ds:imp___got__objc_msgSend]
; endp

I run this on Intel64, so first argument should be stored in rdi register (when we calling block under ARC it is an instance of NSMallocBlock). There is no selector, so second parameter (bool argument) should be stored in rsi register. But rsi register is not used in code - it just sends message _updateSnapshotAndStateRestorationWithAction: to object ds:rdi+0x20 with argument ds:rdi+0x28.

Both ds:rdi+0x20 and ds:rdi+0x28 are captured pointers inside of the block.

I can guess that initially it was implied that this parameter will affect update snapshot function, but actually it isn't. Seems that calling (or not calling) completion influences snapshot and restoration state only.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download