Search code examples
iosswiftwidgettoday-extension

How to detect programmatically when a user enables a widget in Today View


I have an app with a widget, that the user can enable or disable in the iphone's Today View. Is there a way to detect programmatically when a user enables an app extension (widget)? I'd like to count users who install the widget, so i have to catch the exact moment when the user click "enable" in my app (it would be useful catch "disable" action too). Any ideas? Thanks!


Solution

  • Thank you for asking the question.

    When the user allows to widget to show in the notification center, then your widget life cycle method gets called.

    Here you need to manage by flagging some as below For example

    If the widget launches the first time and upload count to the server successfully then your NSUserDefault is set to YES else Set it to NO

    If your app is not launched the first time then do the regular process then no need to upload in the server