# App delegate

**URL:** <https://forum.xojo.com/t/app-delegate/32911>\
**Category:** iOS\
**Created:** [August 11, 2016, 8:49pm UTC](https://forum.xojo.com/t/app-delegate/32911 "2016-08-11T20:49:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Vareilles](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/3be4f8/32.png) [@Pierre\_Vareilles](https://forum.xojo.com/u/Pierre_Vareilles)\
**Post date:** [August 11, 2016, 8:49pm UTC](https://forum.xojo.com/t/app-delegate/32911/1 "2016-08-11T20:49:49Z")

</div>

Does anyone have already try to replace app delegate applicationDidFinishLaunching ?  
I use the code below unsuccessfully. class\_replaceMethod returns false. Delegate like applicationDidBecomeActive or  
applicationWillResignActive work fine.

Thanks for your lights

```auto
// Extract from ImprovediOSApplication class
  Declare Function object_getClass Lib "/usr/lib/libobjc.A.dylib"(cls As Ptr) As Ptr
  Declare Function NSSelectorFromString Lib "Foundation"(aSelectorName As CFStringRef) As Ptr
  Declare Function class_replaceMethod Lib "/usr/lib/libobjc.A.dylib"(cls As Ptr, name As Ptr, imp As Ptr, types As CString) As Boolean
  Declare Function class_addMethod Lib "/usr/lib/libobjc.A.dylib"(cls As Ptr, name As Ptr, imp As Ptr, types As CString) As Boolean
  
  Declare Function sharedApplication Lib "UIKit" selector "sharedApplication"(clsRef As Ptr) As Ptr
  Declare Function NSClassFromString Lib "Foundation"(clsName As CFStringRef) As Ptr
  Declare Function getDelegate Lib "UIKit" selector "delegate"(obj_id As Ptr) As Ptr
  
  Dim appDel As Ptr = getDelegate(sharedApplication(NSClassFromString("UIApplication")))
  Dim appDelegateClass As Ptr = object_getClass(appDel)

 If Not class_replaceMethod(appDelegateClass, NSSelectorFromString("applicationDidFinishLaunching:"), AddressOf impl_didFinishLaunching, "v@:@") Then 
    Break
  End
```

---

<div class="post-metadata">

**Author:** ![Pierre\_Vareilles](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/3be4f8/32.png) [@Pierre\_Vareilles](https://forum.xojo.com/u/Pierre_Vareilles)\
**Post date:** [August 11, 2016, 9:07pm UTC](https://forum.xojo.com/t/app-delegate/32911/3 "2016-08-11T21:07:03Z")

</div>

Make sense. Thanks Jean-Paul

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:25pm UTC](https://forum.xojo.com/t/app-delegate/32911/4 "2020-10-29T18:25:26Z")

</div>


