0

From using this Answer I'm getting this error in swift 4.1, i.e Cannot convert value of type 'Int' to expected argument type 'UnsafeMutablePointer<Int32>!'

var notify_token: Int
notify_register_dispatch("com.apple.springboard.lockstate", notify_token, DispatchQueue.main, { (_ token: Int) -> Void in 
    var state: UInt64 = UINT64_MAX
    notify_get_state(token, state)
    if state == 0 {
        print("unlock device")
    }
    else {
        print("lock device")
    }

How to resolve this?

enter image description here

Sulthan
  • 128,090
  • 22
  • 218
  • 270
Abhishek Mitra
  • 3,335
  • 4
  • 25
  • 46

1 Answers1

1

Try something like this :

var notify_token: Int32

notify_register_dispatch("com.apple.springboard.lockstate", &notify_token, DispatchQueue.main, { (_ token: Int) -> Void in
    var state: UInt64 = UINT64_MAX
    notify_get_state(token, state)
    if state == 0 {
        print("unlock device")
    }
    else {
        print("lock device")
    }
}
Adam
  • 4,266
  • 1
  • 21
  • 21
  • now this `Cannot convert value of type '(Int) -> Void' to expected argument type 'notify_handler_t!' (aka 'ImplicitlyUnwrappedOptional<(Int32) -> ()>')` comes. – Abhishek Mitra May 03 '18 at 09:40
  • now this `Cannot convert value of type '(Int) -> Void' to expected argument type 'notify_handler_t!' (aka 'ImplicitlyUnwrappedOptional<(Int32) -> ()>')` comes. And I changed `(_ token: Int)` to `(_ token: Int32)` and its working but, `var state: UInt64 = UINT64_MAX` `notify_get_state(token, state)` `Cannot convert value of type 'UInt64' to expected argument type 'UnsafeMutablePointer!'` this is appeared. – Abhishek Mitra May 03 '18 at 09:46
  • 2
    You have to give the address so something like this : `notify_get_state(token, &state)` – Adam May 03 '18 at 09:50
  • Well, I figured it out, Edit your Answer and put `var notify_token: Int32` before the function declaration. Then it will start working. Thanks – Abhishek Mitra May 03 '18 at 10:14