Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 application(_:performActionFor:completionHandler:).

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

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

like image 909
matt Avatar asked Sep 16 '16 22:09

matt


1 Answers

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.

Think that the guess with parameter as indicator for snapshot function was wrong.

like image 68
Roman Ermolov Avatar answered Nov 07 '22 04:11

Roman Ermolov