iOS BLE device paired while app is in background or killed or suspend










1















I am able to pair/connect BLE device with my app while app is open. But when my app goes to background/suspended mode, I am not able to keep connection alive.
Is is possible to keep connection alive and get notified for disconnect event for device?










share|improve this question




























    1















    I am able to pair/connect BLE device with my app while app is open. But when my app goes to background/suspended mode, I am not able to keep connection alive.
    Is is possible to keep connection alive and get notified for disconnect event for device?










    share|improve this question


























      1












      1








      1








      I am able to pair/connect BLE device with my app while app is open. But when my app goes to background/suspended mode, I am not able to keep connection alive.
      Is is possible to keep connection alive and get notified for disconnect event for device?










      share|improve this question
















      I am able to pair/connect BLE device with my app while app is open. But when my app goes to background/suspended mode, I am not able to keep connection alive.
      Is is possible to keep connection alive and get notified for disconnect event for device?







      ios ibeacon core-bluetooth






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 16:23









      rmaddy

      242k27316380




      242k27316380










      asked Nov 14 '18 at 12:00









      Nirav PandyaNirav Pandya

      113




      113






















          3 Answers
          3






          active

          oldest

          votes


















          1














          Sure it is.

          First things first: you can scan peripheral and connect to them in background as long as they expose at least one service(this service must be indicated while you are launching the scan command).
          You must specify that in your target capabilities, just by checking Uses Bluetooth LE accessories.

          To detect bluetooth disconnection you just need to implement the CBCentralManagerDelegate method func centralManager(CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?).

          The connection is kept alive in background as long as your peripheral does not require a keep alive signal, if you need to do some operations in background the Uses Bluetooth LE accessories check is required.

          To simplify working with BLE I suggest you to check out this library.






          share|improve this answer






























            0














            For background applications there is limitations. Not all functions may be used in background. Then you send application to moderation with unreasonable background functions you will be failed.



            • Apps that play audible content to the user while in the background,
              such as a music player app

            • Apps that record audio content while in
              the background

            • Apps that keep users informed of their location at all
              times, such as a navigation app

            • Apps that support Voice over Internet
              Protocol (VoIP)

            • Apps that need to download and process new content
              regularly

            • Apps that receive regular updates from external accessories

            Here you will find more description. May be your case is "Apps that receive regular updates from external accessories" with "Acts as a Bluetooth LE accessory" mode.



            In google also you will find a lot of information.






            share|improve this answer






























              0














              For supporting the Core-Bluetooth in suspended / background mode Enable your application for backdrops support.



              Goto your Project --> Target --> Capabilities --> Switch On Background Modes --> Select Use Bluetooth LE accessories.



              But iOS system may kill your background application at any time for free the memory for foreground application.



              For getting the connected/Disconnected events use below line of code.



              central.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnConnectionKey:true, CBConnectPeripheralOptionNotifyOnDisconnectionKey: true])





              share|improve this answer






















                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299770%2fios-ble-device-paired-while-app-is-in-background-or-killed-or-suspend%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                Sure it is.

                First things first: you can scan peripheral and connect to them in background as long as they expose at least one service(this service must be indicated while you are launching the scan command).
                You must specify that in your target capabilities, just by checking Uses Bluetooth LE accessories.

                To detect bluetooth disconnection you just need to implement the CBCentralManagerDelegate method func centralManager(CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?).

                The connection is kept alive in background as long as your peripheral does not require a keep alive signal, if you need to do some operations in background the Uses Bluetooth LE accessories check is required.

                To simplify working with BLE I suggest you to check out this library.






                share|improve this answer



























                  1














                  Sure it is.

                  First things first: you can scan peripheral and connect to them in background as long as they expose at least one service(this service must be indicated while you are launching the scan command).
                  You must specify that in your target capabilities, just by checking Uses Bluetooth LE accessories.

                  To detect bluetooth disconnection you just need to implement the CBCentralManagerDelegate method func centralManager(CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?).

                  The connection is kept alive in background as long as your peripheral does not require a keep alive signal, if you need to do some operations in background the Uses Bluetooth LE accessories check is required.

                  To simplify working with BLE I suggest you to check out this library.






                  share|improve this answer

























                    1












                    1








                    1







                    Sure it is.

                    First things first: you can scan peripheral and connect to them in background as long as they expose at least one service(this service must be indicated while you are launching the scan command).
                    You must specify that in your target capabilities, just by checking Uses Bluetooth LE accessories.

                    To detect bluetooth disconnection you just need to implement the CBCentralManagerDelegate method func centralManager(CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?).

                    The connection is kept alive in background as long as your peripheral does not require a keep alive signal, if you need to do some operations in background the Uses Bluetooth LE accessories check is required.

                    To simplify working with BLE I suggest you to check out this library.






                    share|improve this answer













                    Sure it is.

                    First things first: you can scan peripheral and connect to them in background as long as they expose at least one service(this service must be indicated while you are launching the scan command).
                    You must specify that in your target capabilities, just by checking Uses Bluetooth LE accessories.

                    To detect bluetooth disconnection you just need to implement the CBCentralManagerDelegate method func centralManager(CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?).

                    The connection is kept alive in background as long as your peripheral does not require a keep alive signal, if you need to do some operations in background the Uses Bluetooth LE accessories check is required.

                    To simplify working with BLE I suggest you to check out this library.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 14 '18 at 14:05









                    AndreaAndrea

                    19.7k867106




                    19.7k867106























                        0














                        For background applications there is limitations. Not all functions may be used in background. Then you send application to moderation with unreasonable background functions you will be failed.



                        • Apps that play audible content to the user while in the background,
                          such as a music player app

                        • Apps that record audio content while in
                          the background

                        • Apps that keep users informed of their location at all
                          times, such as a navigation app

                        • Apps that support Voice over Internet
                          Protocol (VoIP)

                        • Apps that need to download and process new content
                          regularly

                        • Apps that receive regular updates from external accessories

                        Here you will find more description. May be your case is "Apps that receive regular updates from external accessories" with "Acts as a Bluetooth LE accessory" mode.



                        In google also you will find a lot of information.






                        share|improve this answer



























                          0














                          For background applications there is limitations. Not all functions may be used in background. Then you send application to moderation with unreasonable background functions you will be failed.



                          • Apps that play audible content to the user while in the background,
                            such as a music player app

                          • Apps that record audio content while in
                            the background

                          • Apps that keep users informed of their location at all
                            times, such as a navigation app

                          • Apps that support Voice over Internet
                            Protocol (VoIP)

                          • Apps that need to download and process new content
                            regularly

                          • Apps that receive regular updates from external accessories

                          Here you will find more description. May be your case is "Apps that receive regular updates from external accessories" with "Acts as a Bluetooth LE accessory" mode.



                          In google also you will find a lot of information.






                          share|improve this answer

























                            0












                            0








                            0







                            For background applications there is limitations. Not all functions may be used in background. Then you send application to moderation with unreasonable background functions you will be failed.



                            • Apps that play audible content to the user while in the background,
                              such as a music player app

                            • Apps that record audio content while in
                              the background

                            • Apps that keep users informed of their location at all
                              times, such as a navigation app

                            • Apps that support Voice over Internet
                              Protocol (VoIP)

                            • Apps that need to download and process new content
                              regularly

                            • Apps that receive regular updates from external accessories

                            Here you will find more description. May be your case is "Apps that receive regular updates from external accessories" with "Acts as a Bluetooth LE accessory" mode.



                            In google also you will find a lot of information.






                            share|improve this answer













                            For background applications there is limitations. Not all functions may be used in background. Then you send application to moderation with unreasonable background functions you will be failed.



                            • Apps that play audible content to the user while in the background,
                              such as a music player app

                            • Apps that record audio content while in
                              the background

                            • Apps that keep users informed of their location at all
                              times, such as a navigation app

                            • Apps that support Voice over Internet
                              Protocol (VoIP)

                            • Apps that need to download and process new content
                              regularly

                            • Apps that receive regular updates from external accessories

                            Here you will find more description. May be your case is "Apps that receive regular updates from external accessories" with "Acts as a Bluetooth LE accessory" mode.



                            In google also you will find a lot of information.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 14 '18 at 13:26









                            Vasily AvilovVasily Avilov

                            5817




                            5817





















                                0














                                For supporting the Core-Bluetooth in suspended / background mode Enable your application for backdrops support.



                                Goto your Project --> Target --> Capabilities --> Switch On Background Modes --> Select Use Bluetooth LE accessories.



                                But iOS system may kill your background application at any time for free the memory for foreground application.



                                For getting the connected/Disconnected events use below line of code.



                                central.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnConnectionKey:true, CBConnectPeripheralOptionNotifyOnDisconnectionKey: true])





                                share|improve this answer



























                                  0














                                  For supporting the Core-Bluetooth in suspended / background mode Enable your application for backdrops support.



                                  Goto your Project --> Target --> Capabilities --> Switch On Background Modes --> Select Use Bluetooth LE accessories.



                                  But iOS system may kill your background application at any time for free the memory for foreground application.



                                  For getting the connected/Disconnected events use below line of code.



                                  central.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnConnectionKey:true, CBConnectPeripheralOptionNotifyOnDisconnectionKey: true])





                                  share|improve this answer

























                                    0












                                    0








                                    0







                                    For supporting the Core-Bluetooth in suspended / background mode Enable your application for backdrops support.



                                    Goto your Project --> Target --> Capabilities --> Switch On Background Modes --> Select Use Bluetooth LE accessories.



                                    But iOS system may kill your background application at any time for free the memory for foreground application.



                                    For getting the connected/Disconnected events use below line of code.



                                    central.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnConnectionKey:true, CBConnectPeripheralOptionNotifyOnDisconnectionKey: true])





                                    share|improve this answer













                                    For supporting the Core-Bluetooth in suspended / background mode Enable your application for backdrops support.



                                    Goto your Project --> Target --> Capabilities --> Switch On Background Modes --> Select Use Bluetooth LE accessories.



                                    But iOS system may kill your background application at any time for free the memory for foreground application.



                                    For getting the connected/Disconnected events use below line of code.



                                    central.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnConnectionKey:true, CBConnectPeripheralOptionNotifyOnDisconnectionKey: true])






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 20 '18 at 7:08









                                    iOS_MaccusiOS_Maccus

                                    30710




                                    30710



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299770%2fios-ble-device-paired-while-app-is-in-background-or-killed-or-suspend%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        這個網誌中的熱門文章

                                        How to read a connectionString WITH PROVIDER in .NET Core?

                                        In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                        Museum of Modern and Contemporary Art of Trento and Rovereto