0

I have a Today Widget for my app that when tapped launches the containing app. The problem is that it seems to be 'over-sensitive'. Sometimes when I am just scrolling, the widget recognises this as a tap and launches the app.

Here is my code:

    @IBAction func launchApp(sender: AnyObject) {
    var url: NSURL = NSURL.URLWithString("AffordItLauncher://")
    self.extensionContext?.openURL(url, completionHandler: nil)
}

There is basically a button over the top of the entire widget.

How can I fix this?

user3746428
  • 11,047
  • 20
  • 81
  • 137

1 Answers1

1

What touch event type triggers the above function? Normally you'd want to use something like UIControlEventTouchUpInside in order to ensure the event isn't fired until you touch inside a control element, and lift your finger.

Rob Glassey
  • 2,237
  • 20
  • 21
  • I am using TouchUpInside... It does seem to fire when I lift my finger, but the problem is that it does this even if I touch my finger on the widget to scroll in Notification Centre and then it fires as soon as I lift my finger to stop scrolling. – user3746428 Oct 06 '14 at 23:35
  • The problem is somewhere in your event handling - is it a 'proper' UIButton, or are you handling touches in a custom fashion? If custom, you'll need to look at things like detecting touch down within an element first, then cancelling should the touch change to a pan, be long enough to be considered a long-press rather than a tap, or move outside an element etc. There is not enough information in the above code - your code sample isn't fundamentally wrong, it's how that code is being triggered that's the issue. – Rob Glassey Oct 06 '14 at 23:45