Giter VIP home page Giter VIP logo

ancs4linux's Introduction

iOS/iPadOS notification service client for Linux desktop

This project lets you receive iOS and iPadOS notifications on your Linux desktop/laptop. No jailbreak needed. Work in progress. Feedback needed. Reddit thread.

Photo of running script

It uses Apple Notification Center Service (ANCS) - the same protocol that smartwatches use. I'm also considering implementing Apple Media Service (AMS), which allows controlling media playing on the phone, and redirecting phone audio to PC. Please let me know if it would be useful to anyone. I think redirecting calls to PC should also be possible (by having PC act as headset), but I don't have the need for that much tinkering.

Alternatives:

Installation and usage

  1. Install Python 3.7 and python3-dbus (Ubuntu) / python-dbus (Arch). You probably have that library already installed. I'm not sure whether Python 3.7 is necessary, but I haven't tested the program with earlier versions.
  2. Download main.py and make it executable. You may also want to download/configure handlers directory and its content (but the script will run without it just fine, though).
  3. Pair and connect your phone with your PC (see #Pairing).
  4. Start ./main.py (current working directory matters) and watch for its output to see if there's anything wrong. If nothing comes out, you may need to wait ~30 seconds for a timeout error that will hopefully contain the details you'll need to solve the problem.
  5. Try sending yourself a notification. Shortcuts app is a great way to do it.

Pairing

The most reliable method I found:

  • Unpair your devices ("Forget this device" in iOS Settings).
  • Download and unpack bluez-5.43 source.
  • Start blueman (Bluetooth Manager).
  • If you have multiple Bluetooth cards: edit the for loop in find_adapter in /test/example-advertisement.
  • Use the free nRF Connect app to connect to your PC (it will advertise itself as a heart sensor). It should look like this, click Connect there.
  • blueman will now handle pairing (compare PINs).
  • You are connected now, you can run ./main.py, the phone will display a popup whether to grant notification access to the PC.

The success rate and pairing steps depend on your Bluetooth card. My Intel Wireless-AC 9462 card does not work, so I bought ASUS USB-BT400 card, it works fine. My previous Intel WiFi+BT card worked, but I don't remember the model and I sold that laptop already.

Since it's Bluetooth we are talking about, it works only when the stars are aligned correctly. If it worked yesterday but you can't even see your device today, restart both your PC and your phone. On a positive side, though, you can be connected to many BLE devices at once. I don't have Apple Watch to test it, but at least the AirPods still work when using this script.

It looks like iOS will forget about PC permissions/capabilities after a while (a week?), so the pairing has to be repeated.

I found that I can sometimes initiate the connection from PC side by connecting to iOS random BLE address. I was using hcitool blescan to do that (put the device close to the PC and it will become obvious which device is yours).

Configuration

There are currently 2 options you can tweak:

./main.py -h
usage: main.py [-h] [--hci INT] [--resolution INT]

optional arguments:
  -h, --help        show this help message and exit
  --hci INT         use Bluetooth hciX (default 0, see `hcitool dev')
  --resolution INT  polling rate (default 20 per second)

If you have only 1 Bluetooth card in your laptop/PC, you will probably be fine with default (0) hci index. Resolution is due to polling main loop (it doesn't need to shouldn't be there). On my CPU (Intel i5-6300HQ), setting resolution to 100 causes 2% CPU usage. I found 20 to be nice balance between CPU usage and notification drop rate (I don't get notifications less that 5 ms apart of each other too often, only WhatsApp is a potential "danger").

You can put executable files in handlers directory. Currently there are 2 handlers supported - battery and notification. These files can be absent, and are searched for based on the current working directory. Check out the default handlers - they are simple shell scripts.

You may want to run main.py in an infinite loop, as it will quit on error. For example:

while true; do ./main.py; sleep 5; done

Contributing

The code is a mess and I started a total rewrite. Ruby dbus gem is much more pleasant than Python's lib. But before that, I would like to understand iOS Bluetooth stack more.

Initially I tried using bluepy, but I couldn't get iPhone to pair (setSecurityLevel("medium")).

Useful tools: bluetoothctl (menu gatt), qdbusviewer (part of qt5-tools on Arch).

The pairing process needs to be integrated. We can either do whatever example-advertisement does, or salvage the ble-ancs project.

Sending iMessage messages would be useful too, and it should be possible over "regular" (2.0) Bluetooth via Message Access Profile.

ancs4linux's People

Contributors

pzmarzly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.