<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to setup &amp;quot;Immediate Service alert client&amp;quot; iOS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21684/how-to-setup-immediate-service-alert-client-ios</link><description>How do you setup &amp;quot;immediate Service Alert&amp;quot; Client on iOS, in order to get notified when an action is taken on the bluetooth peripheral ? (eg. Button press)</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Apr 2017 12:00:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21684/how-to-setup-immediate-service-alert-client-ios" /><item><title>RE: How to setup "Immediate Service alert client" iOS</title><link>https://devzone.nordicsemi.com/thread/85176?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 12:00:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9445efd7-ba48-46cf-adf6-929eef862734</guid><dc:creator>Mostafa Berg</dc:creator><description>&lt;p&gt;No problems, glad to help !, remember to mark as solved if it worked for you so people coming from google searches see that this has a solution :) thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to setup "Immediate Service alert client" iOS</title><link>https://devzone.nordicsemi.com/thread/85175?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 11:59:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0d0cb3a-1ea8-4922-8d9f-ef52786e4f66</guid><dc:creator>raphael</dc:creator><description>&lt;p&gt;Thank you very much for this detailed answer ! Now everything makes sense!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to setup "Immediate Service alert client" iOS</title><link>https://devzone.nordicsemi.com/thread/85174?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 11:17:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08ad6bd3-fce1-4913-bb5f-1ee069766257</guid><dc:creator>Mostafa Berg</dc:creator><description>&lt;p&gt;Hi Raphael, thanks for getting in touch!&lt;/p&gt;
&lt;p&gt;You can use the nRFToolbox app as an implementation guide, the service UUID you&amp;#39;re looking at is available on &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/Utilities/NORServiceIdentifiers.swift#L49"&gt;this line here&lt;/a&gt; with the UUID of &lt;code&gt;1802&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;###First way: Event from phone to peripheral, AKA &amp;quot;&lt;em&gt;Find me&lt;/em&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll need to start scanning for this service identifier, general scanning procedure can be &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/Scanner/NORScannerViewController.swift#L111"&gt;seen here&lt;/a&gt;, simply replace the service identifier with the one you&amp;#39;re targeting.&lt;/p&gt;
&lt;p&gt;after connecting and getting the peripheral, follow the service discovery procedure &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L250"&gt;found here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;and after getting the targeted service, discover it&amp;#39;s characteristics as &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L307-L308"&gt;done here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you&amp;#39;re almost set, when the characteristic is discovered, hold a reference to it, as a class properties for example, you can &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L331-L336"&gt;see how we do that here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;and when you tap the button on your phone, or call the &amp;quot;Find me&amp;quot; method, this will write to the characteristic the values you can &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L44-L52"&gt;see here&lt;/a&gt;, to trigger the event on the peripheral, this will usually make the peripheral play a sound or do any other predefined action.&lt;/p&gt;
&lt;p&gt;###Second way: Event from peripheral to phone
###(This answers your question)&lt;/p&gt;
&lt;p&gt;if you want to do things the other way, you need to reverse the roles, you need to create a class that has a &lt;code&gt;CBPeripheralManager&lt;/code&gt;property and implements the &lt;code&gt;CBPeripheralManagerDelegate&lt;/code&gt;, those methods are &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L373-L423"&gt;referenced here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After that you need to implement the immediate alert service on your own &amp;quot;peripheral&amp;quot; (your iPhone in this case), &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L129-L134"&gt;seen at this step&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You also need to &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L136-L143"&gt;add the Alert level characteristic into the service with UUID &lt;code&gt;2A06&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once you have that in place, pressing the button on your BLE device will trigger the delegate method:
&lt;code&gt;peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest])&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can &lt;a href="https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/blob/master/nRF%20Toolbox/PROXIMITY/NORProximityViewController.swift#L396-L419"&gt;see the full body of the function here&lt;/a&gt; to see how the data is parsed and how to take action depending on type of event.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.immediate_alert.xml"&gt;Here&lt;/a&gt; is the reference to the immediate alert service for future reference&lt;/p&gt;
&lt;p&gt;This should set you on the right path, if you have any other issues, don&amp;#39;t hesitate to ask!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>