Setup custom Haptic with latest Swift for iPhone7 and up





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















After reading about it, I have some mess in my head.



This function is being called while user swipe his finger on some UI element :



func wasDragged() { signal here }


I would like to make small Haptic signals every time it's being called ( like a dates picker wheel )




  1. How would I setup first time and make the signals of the Haptic Engine on call ?

  2. Do I have to check for device kind ? I want it only on iPhone 7 and up.


Using latest Swift.










share|improve this question





























    0















    After reading about it, I have some mess in my head.



    This function is being called while user swipe his finger on some UI element :



    func wasDragged() { signal here }


    I would like to make small Haptic signals every time it's being called ( like a dates picker wheel )




    1. How would I setup first time and make the signals of the Haptic Engine on call ?

    2. Do I have to check for device kind ? I want it only on iPhone 7 and up.


    Using latest Swift.










    share|improve this question

























      0












      0








      0








      After reading about it, I have some mess in my head.



      This function is being called while user swipe his finger on some UI element :



      func wasDragged() { signal here }


      I would like to make small Haptic signals every time it's being called ( like a dates picker wheel )




      1. How would I setup first time and make the signals of the Haptic Engine on call ?

      2. Do I have to check for device kind ? I want it only on iPhone 7 and up.


      Using latest Swift.










      share|improve this question














      After reading about it, I have some mess in my head.



      This function is being called while user swipe his finger on some UI element :



      func wasDragged() { signal here }


      I would like to make small Haptic signals every time it's being called ( like a dates picker wheel )




      1. How would I setup first time and make the signals of the Haptic Engine on call ?

      2. Do I have to check for device kind ? I want it only on iPhone 7 and up.


      Using latest Swift.







      swift






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 7:43









      CurneliousCurnelious

      3,913752105




      3,913752105
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The documentation oh Haptic feedback is really descriptive.
          But if you want some quick solution here it is.



          var hapticGenerator: UISelectionFeedbackGenerator?

          func wasDragged() {

          hapticGenerator = UISelectionFeedbackGenerator()
          haptiGenerator.selectionChanged()
          hapticGeneraor = nil

          }


          Alternatively depending on the logic of the screen, you can initialize generator outside of wasDragged function and inside of it just call hapticGenerator.prepare() and selectionChanged(). In that case you should not assign nil to it after the dragging is complete because it won't get triggered again. As per documentation you have to release generator when no longer needed as Taptic Engine will wait and therefore consume system resources for another call.




          Note that calling these methods does not play haptics directly.
          Instead, it informs the system of the event. The system then
          determines whether to play the haptics based on the device, the
          application’s state, the amount of battery power remaining, and other
          factors.




          For example, haptic feedback is currently played only:




          • On a device with a supported Taptic Engine

          • When the app is running in the foreground

          • When the System Haptics setting is enabled


          Documentation:



          https://developer.apple.com/documentation/uikit/uifeedbackgenerator






          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%2f53426061%2fsetup-custom-haptic-with-latest-swift-for-iphone7-and-up%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The documentation oh Haptic feedback is really descriptive.
            But if you want some quick solution here it is.



            var hapticGenerator: UISelectionFeedbackGenerator?

            func wasDragged() {

            hapticGenerator = UISelectionFeedbackGenerator()
            haptiGenerator.selectionChanged()
            hapticGeneraor = nil

            }


            Alternatively depending on the logic of the screen, you can initialize generator outside of wasDragged function and inside of it just call hapticGenerator.prepare() and selectionChanged(). In that case you should not assign nil to it after the dragging is complete because it won't get triggered again. As per documentation you have to release generator when no longer needed as Taptic Engine will wait and therefore consume system resources for another call.




            Note that calling these methods does not play haptics directly.
            Instead, it informs the system of the event. The system then
            determines whether to play the haptics based on the device, the
            application’s state, the amount of battery power remaining, and other
            factors.




            For example, haptic feedback is currently played only:




            • On a device with a supported Taptic Engine

            • When the app is running in the foreground

            • When the System Haptics setting is enabled


            Documentation:



            https://developer.apple.com/documentation/uikit/uifeedbackgenerator






            share|improve this answer






























              1














              The documentation oh Haptic feedback is really descriptive.
              But if you want some quick solution here it is.



              var hapticGenerator: UISelectionFeedbackGenerator?

              func wasDragged() {

              hapticGenerator = UISelectionFeedbackGenerator()
              haptiGenerator.selectionChanged()
              hapticGeneraor = nil

              }


              Alternatively depending on the logic of the screen, you can initialize generator outside of wasDragged function and inside of it just call hapticGenerator.prepare() and selectionChanged(). In that case you should not assign nil to it after the dragging is complete because it won't get triggered again. As per documentation you have to release generator when no longer needed as Taptic Engine will wait and therefore consume system resources for another call.




              Note that calling these methods does not play haptics directly.
              Instead, it informs the system of the event. The system then
              determines whether to play the haptics based on the device, the
              application’s state, the amount of battery power remaining, and other
              factors.




              For example, haptic feedback is currently played only:




              • On a device with a supported Taptic Engine

              • When the app is running in the foreground

              • When the System Haptics setting is enabled


              Documentation:



              https://developer.apple.com/documentation/uikit/uifeedbackgenerator






              share|improve this answer




























                1












                1








                1







                The documentation oh Haptic feedback is really descriptive.
                But if you want some quick solution here it is.



                var hapticGenerator: UISelectionFeedbackGenerator?

                func wasDragged() {

                hapticGenerator = UISelectionFeedbackGenerator()
                haptiGenerator.selectionChanged()
                hapticGeneraor = nil

                }


                Alternatively depending on the logic of the screen, you can initialize generator outside of wasDragged function and inside of it just call hapticGenerator.prepare() and selectionChanged(). In that case you should not assign nil to it after the dragging is complete because it won't get triggered again. As per documentation you have to release generator when no longer needed as Taptic Engine will wait and therefore consume system resources for another call.




                Note that calling these methods does not play haptics directly.
                Instead, it informs the system of the event. The system then
                determines whether to play the haptics based on the device, the
                application’s state, the amount of battery power remaining, and other
                factors.




                For example, haptic feedback is currently played only:




                • On a device with a supported Taptic Engine

                • When the app is running in the foreground

                • When the System Haptics setting is enabled


                Documentation:



                https://developer.apple.com/documentation/uikit/uifeedbackgenerator






                share|improve this answer















                The documentation oh Haptic feedback is really descriptive.
                But if you want some quick solution here it is.



                var hapticGenerator: UISelectionFeedbackGenerator?

                func wasDragged() {

                hapticGenerator = UISelectionFeedbackGenerator()
                haptiGenerator.selectionChanged()
                hapticGeneraor = nil

                }


                Alternatively depending on the logic of the screen, you can initialize generator outside of wasDragged function and inside of it just call hapticGenerator.prepare() and selectionChanged(). In that case you should not assign nil to it after the dragging is complete because it won't get triggered again. As per documentation you have to release generator when no longer needed as Taptic Engine will wait and therefore consume system resources for another call.




                Note that calling these methods does not play haptics directly.
                Instead, it informs the system of the event. The system then
                determines whether to play the haptics based on the device, the
                application’s state, the amount of battery power remaining, and other
                factors.




                For example, haptic feedback is currently played only:




                • On a device with a supported Taptic Engine

                • When the app is running in the foreground

                • When the System Haptics setting is enabled


                Documentation:



                https://developer.apple.com/documentation/uikit/uifeedbackgenerator







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 8:08

























                answered Nov 22 '18 at 8:00









                inokeyinokey

                1,120919




                1,120919
































                    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%2f53426061%2fsetup-custom-haptic-with-latest-swift-for-iphone7-and-up%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







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents