iOS Tutorial [Tool] iWidget - add a today widget to your App

Discussion in 'iOS Tutorials' started by JanPRO, Apr 26, 2018.

  1. JanPRO

    JanPRO Well-Known Member Licensed User

    iWidget is a (experimental) tool which allows you to add a today widget to your B4i app.

    How to use?
    1. Download iWidget here
    2. Close the B4i IDE
    3. You need to fill in the following information
      • the path of the B4i installation directory
      • the path of the B4i project you want to add the widget to
      • the name of your App (corresponds to the #ApplicationLabel)
      • the package name of your App (corresponds to the Package under the Build Configurations)
      • a title for the widget
      • choose a port for the logger (see the explanation of the logger in the notes section)
    4. Click on the Apply button
    5. Open the B4i project
    6. Add the attached modules (TodayWidget & WidgetContext) to your project
    7. if you use the logger don't forget to set Logger_Host & Logger_Port variables
    8. Start coding your widget :)

    Notes & tips:
    • start with the attached HelloWorld project, for the first time it's possible that you have to add the widget manually by clicking on the circled edit button
    • use a wildcard certificate for your project
    • the minimum required iOS version is 10, so add: #MinVersion: 10 to your project attributes
    • always keep in mind the consequences of the fact, that a widget is a totally new target. For example the widget can't access values of a variable, which were set in the main app
    • the PerformUpdate event is invoked when the widget is loaded and it can also be called in the background. In this sub you need to check whether there is new data available and update your UI. From my experience you should do the same routine also in the Widget_Appear sub
    • I strongly recommend to create the UI with the designer and use anchors
    • the normal Log method will be useless for widgets. Instead make use of the Wlog function in the TodayWidget module
    • the logger will not catch errors: If your widget returns "Unable to load" there is a mistake in your code, use try-catch blocks to locate the issue. However, if you have a local mac, you can open the generated Xcode project and run the Widget target specifically (in this case you will be able to see the logs added with the normal Log method and also see errors)
    • when working on a widget always test in release mode
    • everytime you activate or deactivate iWidget you have to restart B4i
    • when working on your widget project, keep iWidget open
    • administrator rights are required for editing the Xcode template

    • iWidget was tested with B4i v.4.81 + local mac builder (Xcode 9.2), I don't know whether the hosted builder has restrictions concerning the template file, just try it out ;)

    Feel free to ask questions ;)

    Attached Files:

    Last edited: Apr 27, 2018
    moster67, ilan, walterf25 and 5 others like this.
  2. walterf25

    walterf25 Well-Known Member Licensed User

    This is really cool, just tried and it's so easy to set it up, one question though, how does the Update work, I see that in your example the time gets updated every minute, but how is that controlled, can it be set up to update every so often, or how do I control that?

    Thanks for this, I will add it to one of my apps right away, but will wait for your reply on the Update question..
  3. tufanv

    tufanv Expert Licensed User

    You are adding very critical tools for us for b4i. Thanks very much !!
    JanPRO and ilan like this.
  4. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi Walter,
    first of all, sorry for the super late reply, but it's kind of busy around here. I am glad, you like this project :)
    The answer is simple: the update frequency is controlled by Apple, you don't have influence on it. Also take a look at the following post:
    I recommend to always update your UI in the PerformUpdate and Widget_Appear sub, because the appear event is called every time the widget is displayed. Moreover, if you have time critical content you should add a small refresh button/icon to your UI.

    Thank you very much Tufan. I know that these kind of tools (see also "Swifter") may look impractical at first glance, however they demonstrate the potential of B4i.

    Have a great 2019

    Erel likes this.
  5. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    Is there any possible way to see the source code of the desktop application? It would be pretty neat to see how it works.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice