2

I am working on an objective-c project that uses a C++ library. It keeps listening to users' audio input using Audio Queue and pass the data to the C++ library. Eventually, the C++ library will trigger a call-back function when it finds a whole sentence.

But the problem is that my application containing several views, and I want the top view to get notified immediately. I passed a callback function to the C++ library, but I don't know where should I define such a function because I want to it to have access to the user's current view controller and change content on it.

I am wondering if I should put it in UINavigationController or AppDelegate. Any idea will be appreciated!

Patroclus
  • 1,163
  • 13
  • 31
  • I suggest to use UIView and to add directly on App window, by keeping reference with Appdelegate to access globally. – max9xs Jul 11 '18 at 20:45
  • @max9xs You mean add a subview to every view? And then create references in Appdelegate, right? – Patroclus Jul 11 '18 at 20:47
  • It is probably easier to use `NSNotification` to loosely couple the C++ code and your view controllers – Paulw11 Jul 11 '18 at 20:48
  • No. AppWindow=[[[UIApplication sharedApplication] delegate] window]; – max9xs Jul 11 '18 at 20:49
  • 1
    You can use NSNotification to receive callbacks in your every view controllers. – max9xs Jul 11 '18 at 20:49
  • @Paulw11 So I should send a notification in C++ code and make all the views be a listener? Is this correct? Not familiar with NSNotifaction... – Patroclus Jul 11 '18 at 20:58
  • @Paulw11But my library is pure C++, how could I use NSNotification in it? Don't want to rename to .mm – Patroclus Jul 11 '18 at 20:59
  • @WanhuiQiao If you place one UIView on App window. It will be remain on top of all view controller. You need not to create many instances. Your UIView and view controllers both will be using ObejctiveC or swift. So you can send receive data between them. – max9xs Jul 11 '18 at 21:14
  • I am not sure, I have never used C++ but if your framework can communicate with a UIViewController then presumably it can communicate with a helper objective-C object that can post the notification for you. – Paulw11 Jul 11 '18 at 21:18
  • @max9xs Is there any documentation about it? I never directly use App window before. I would really appreciate it! – Patroclus Jul 11 '18 at 21:25
  • @WanhuiQiao sorry but I came to know about this approach from stack overflow only. Also there are lot of third party alerts, toast controls uses window as parent. – max9xs Jul 11 '18 at 21:38
  • @WanhuiQiao https://stackoverflow.com/questions/29160540/how-to-add-view-in-uiwindow – max9xs Jul 11 '18 at 21:40

0 Answers0