# Call native iOS in UNO in button click event handler

**URL:** <https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305>\
**Category:** How-to Discussions\
**Created:** [October 8, 2015, 10:22pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305 "2015-10-08T22:22:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kfi/32/440_2.png) [@kfi](https://forums.fusetools.com/u/kfi)\
**Post date:** [October 8, 2015, 10:22pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/1 "2015-10-08T22:22:45Z")

</div>

Hi,

How would one use Uno in a project to call this iOS code

- (IBAction) playSystemSound: (id) sender {

In a button click handler?

Best regards

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [October 8, 2015, 11:07pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/2 "2015-10-08T23:07:52Z")

</div>

Hi!

To call Uno methods from UX markup instead of JS, you simply drop the `{}` brackets:

```auto
<Button Clicked="MethodName" />

```

And in your code behind `.ux.uno` file:

```auto
public partial class NameOfClass
{
    void MethodName(object sender, Uno.EventArgs args)
    {
        iOS.AudioToolbox.Functions.AudioServicesPlaySystemSound(1100);
    }
}

```

Make sure you add reference to the `iOS` and `ObjC` packages in your project.

---

<div class="post-metadata">

**Author:** ![kfi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kfi/32/440_2.png) [@kfi](https://forums.fusetools.com/u/kfi)\
**Post date:** [October 9, 2015, 4:44am UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/3 "2015-10-09T04:44:49Z")

</div>

Hi,

That sure looks simple 😃 When I try to buil dI get this error:

iOS.AudioToolbox does not contain type or namespace ‘AudioServicesPlaySystemSound’. Could you be missing a package reference?

Any ideas?

Best Kenneth

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [October 9, 2015, 6:08am UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/4 "2015-10-09T06:08:44Z")

</div>

Ah, whops, i forgot the static `Functions` class there. I’ve updated my above post

---

<div class="post-metadata">

**Author:** ![kfi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kfi/32/440_2.png) [@kfi](https://forums.fusetools.com/u/kfi)\
**Post date:** [October 9, 2015, 8:11am UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/5 "2015-10-09T08:11:28Z")

</div>

Hmm strange now it just says iOS.AudioToolbox does not contain type or namespace ‘Functions’

---

<div class="post-metadata">

**Author:** ![Vegard\_Strand\_Lende](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/vegard_strand_lende/32/349_2.png) [@Vegard\_Strand\_Lende](https://forums.fusetools.com/u/Vegard_Strand_Lende)\
**Post date:** [October 9, 2015, 12:33pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/6 "2015-10-09T12:33:03Z")

</div>

Hi!

Since we are dealing with platform specific code we need to add some more stuff here to get it to work 🙂

Platform specific code can be mixed with platform agnostic code quite easily in UNO. Ill show you some examples for your case 🙂

```auto
public partial class NameOfClass
{
        extern (!Mobile) void MethodName(object sender, Uno.EventArgs args)
        {
            // Do some non mobile stuff :)
        }

        extern (Android) void MethodName(object sender, Uno.EventArgs args)
        {
            // Do some android stuff
        }

        extern (iOS) void MethodName(object sender, Uno.EventArgs args)
        {
            global::iOS.AudioToolbox.Functions.AudioServicesPlaySystemSound(1100);
        }
}

```

In the above example only the method with the appropirate condition for you export target will be included in the compile. So if you build for iOS then only the method with `extern (iOS)` will be included.

Another easy way:

```auto
public partial class NameOfClass
{
        void MethodName(object sender, Uno.EventArgs args)
        {
              if !defined(Mobile)
              {
                  // Do some non mobile stuff :)    
              }
              else if defined(Android)
              {
                  // Do some android stuff
              }
              else if defined(iOS)
              {
                  global::iOS.AudioToolbox.Functions.AudioServicesPlaySystemSound(1100);    
              }
        }
}

```

Try this and get back to me if it didnt work 🙂

---

<div class="post-metadata">

**Author:** ![kfi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kfi/32/440_2.png) [@kfi](https://forums.fusetools.com/u/kfi)\
**Post date:** [October 9, 2015, 3:05pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/7 "2015-10-09T15:05:53Z")

</div>

That worked!! Thanks a lot, I have made a gist with a project demo of it for other people finding this thread: [https://gist.github.com/kfiil/d5bd1d4a046d3af9e51a](https://gist.github.com/kfiil/d5bd1d4a046d3af9e51a)

---

<div class="post-metadata">

**Author:** ![Vegard\_Strand\_Lende](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/vegard_strand_lende/32/349_2.png) [@Vegard\_Strand\_Lende](https://forums.fusetools.com/u/Vegard_Strand_Lende)\
**Post date:** [October 9, 2015, 3:21pm UTC](https://forums.fusetools.com/t/call-native-ios-in-uno-in-button-click-event-handler/6305/8 "2015-10-09T15:21:38Z")

</div>

Good stuff 🙂
