---
title: "Call Back funtion handling"  
description: "Call Back funtion handling"  
author: "Anonymous User"  
published: 2015-10-14  
updated: 2015-10-14  
canonical: https://www.mindstick.com/forum/33510/call-back-funtion-handling  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Call Back funtion handling

I have created 2 callback [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) in Obj-C, first [callback function](https://www.mindstick.com/forum/157808/what-is-a-callback-function-and-how-is-it-used-in-javascript) [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why) but 2nd callback function generating problem.\
Please help whats going [wrong](https://answers.mindstick.com/qa/48468/who-wrote-the-the-wrong-enemy-america-in-afghanistan-2001-2014-and-when)?\
For example:

```
cb = IOServiceAddMatchingNotification(notifyPort, firstMatchNotification,                                     matchingDict, RawDeviceAdded, NULL,                                     &gRawAddedIter);RawDeviceAdded(NULL, gRawAddedIter, self);
```

This works fine. But below function receives [self](https://www.mindstick.com/articles/44535/smart-ways-to-secure-self-storage-facilities) as nil.

```
cb = IOServiceAddMatchingNotification(notifyPort, firstMatchNotification,                                     matchingDict,BulkTestDeviceAdded,NULL,                                     &gBulkTestAddedIter);BulkTestDeviceAdded(NULL, gBulkTestAddedIter, self);
```

## Replies

### Reply by Tarun Kumar

I am guessing that you are using a common method to handle [callback](https://www.mindstick.com/articles/152/using-the-callback) functions, it’s a static [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) that forwards your instance using callback.\
Ok, here I try to solve your problem, I think it’s useful for you, here is the code:

```
static RawDeviceAdded(void* refcon, io_iterator_t iterator) {    [(MyClass*)refcon rawDeviceAdded:iterator];}@implementation MyClass- (void)setupCallbacks {    // ... all preceding setup snipped    cb = IOServiceAddMatchingNotification(notifyPort,firstMatchNotification, matchingDict, RawDeviceAdded, (void*)self, &gRawAddedIter );    // call the callback method once to 'arm' the iterator    [self rawDeviceAdded:gRawAddedIterator];}- (void)rawDeviceAdded:(io_iterator_t)iterator {    // take care of the iterator here, making sure to complete iteration to re-arm it}@end
```


---

Original Source: https://www.mindstick.com/forum/33510/call-back-funtion-handling

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
