Get data from iOS

Posted on
  • Hi,

    I know that Bangle can receive notifiactions directly from iOS but I wonder if there is possibility to make an app for example to "capture" data from secific notifiction e.g. weather app that gets data from ios Shortcuts with weather data in json format.

    Is it somehow possible?

  • So the Bangle is getting the relevant notification sent to it, and you want to be able to grab the data out of it?

    If so, absolutely! The ios app sends the message event to the messages library at https://github.com/espruino/BangleApps/b­lob/master/apps/ios/boot.js#L165 but the messages library sends a message event, so if you had an app with that did:

    Bangle.on("message", function(type, msg) {
      if (msg.src.toLowerCase().includes("weather­")) {
        ....do stuff here
        msg.handled = true; // stop us loading the messages app or buzzing
      }
    });
    

    That should work great for you

  • Cool

  • Cool I will explore it.
    But already found problem. When using message overlay app I can't get any data. With standaard message apps I can save data from notifications to storage.
    Is it about boot order or something?

  • Where have you written that code? Is it in an app, or boot code?

    If it's an app then if a different app gets loaded your app's code won't get called - could that be it?

    I'm not sure how message overlay works - I assumed it didn't load another app, but I might be wrong

  • It does not load another app, but it does not yet use the message events. It overrides the require call for the messages lib which is quite hacky. Boot order won't save that, only updating messages overlay to correctly using the messages event will help.
    I wanted to have a go at updating messages overlay anyway since it does not work correctly with navigation messages. If you want to help out with that feel free to do so, otherwise I fear you will have to wait until I find some spare time :)

  • What if we added this to the "iOS Integration" app and provided iphone shortcuts to automatically send over data via a notification (such as weather, reminders, calendar events) in lieu of Gadgetbridge for iphones.

    I would most likely be able to implement this. I am wondering if it has already been done and any suggestions/requirements.

  • and provided iphone shortcuts to automatically send over data via a notification (such as weather, reminders, calendar events) in lieu of Gadgetbridge for iphones.

    I wasn't aware you could do this - but if you can set that up on iOS then great! I'm happy to help with stuff on the Bangle.js side of things

  • Would this be better implemented as its own app or should I try to add it to the existing iOS integration app?

    I think it would be easier to add it to the existing app

  • Yes, I'd just add to the existing iOS app - but some good info on how to set up iOS to get the notifications would be amazingly helpful.

  • I created this shortcut for calendar syncing.
    https://www.icloud.com/shortcuts/6ed39f5­2d9634359954d546731c5d4c9
    This sends notifications with the format

    {
    "title": "<title>",
    "start_time": "<ISO 8601 timestamp>",
    "duration": "HH:MM:SS",
    "notes": "<description>",
    "location": "location text/address", 
    "calName": "<calendar name>"
    }
    

    I could not get the calendar color through the shortcuts app.

    Attached is an image of a test run.

    Would it be possible to run the "negative action" to automatically dismiss the notifications?

    This shortcut is automatable with the shortcut "automations" feature. It can be configured to run at a time of day or when the bangle is connected to the iphone.

    I will make another shortcut for weather.


    1 Attachment

    • Captură de ecran din 2023-11-08 la 11.11.28.jpeg
  • This looks really neat!

    Would it be possible to run the "negative action" to automatically dismiss the notifications?

    Yes, the Bangle cal just call NRF.ancsAction(..., false) to dismiss it automatically: https://www.espruino.com/Reference#l_NRF­_ancsAction

  • Thanks!

    I'm noticing that a lot of apps require an android.calendar.json file and I'm not sure what to do.
    I also can't seem to figure out what the standard weather library looks like or how to update data.

    Not sure what to do about android vs ios calendars. It would be great to have one app/module/file that both ios and android depended on, but that is a bit out of my current capabilities

    Could you send a link to either documentation of the weather module and/or how it is implemented for android?

  • Ahh - I'd ignore the fact it says android.calendar.json and just write into it with the data yourself. We can always rename the file later.

    The main weather library is at https://github.com/espruino/BangleApps/b­lob/master/apps/weather/lib.js and reads from weather.json. I believe the rough format is in https://www.espruino.com/Gadgetbridge if you search for weather there:

    temp,hi,lo,hum,rain,uv,code,txt,wind,wdi­r,loc - weather report (current temp, days highest temp, days lowest temp, current humidity, rain/precip probability, UV Index, current condition code, current condition text, wind speed, wind direction)

    Sorry it's not better documented though - you can see roughly what form the data takes at https://github.com/espruino/BangleApps/b­lob/master/apps/weather/clkinfo.js

  • I tested and this works pretty well.

    Thanks for all your help!!!

    For future readers: https://github.com/espruino/BangleApps/p­ull/3089

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Get data from iOS

Posted by Avatar for user146550 @user146550

Actions