ancs_go

package module
v0.0.0-...-7b07208 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

ancs_go

运行在树莓派上,用于获取iphone通知内容

需要树莓派有蓝牙功能

1. 将树莓派与手机配对

树莓派中依次运行

   bluetoothctl
   power on
   agent on

等待终端中出现手机的蓝牙名称 扫描到后执行

配对完成后记录下手机蓝牙的地址

    trust xx:xx:xx:xx:xx
    pair xx:xx:xx:xx:xx
2. 运行

下面代码中

dev_xx_xx_xx_xx_xx_xx

修改为你的蓝牙id,蓝牙id中的冒号修改为下划线,如:蓝牙id为 DF:SD:QW:3S:SD 改为 dev_DF_SD_QW_3S_SD

func main() {
	ancs, err := NewAncs("/org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx")
	if err != nil {
		panic(err)
	}
	err = ancs.StartNotify()
	if err != nil {
		fmt.Println(err)
	}

	for {
		select {
		case notification := <-ancs.NotificationChan:
			fmt.Println(notification.Original)
			err := ancs.GetNotificationAttributes(notification)
			if err != nil {
				fmt.Println(err.Error())
			}
		case data := <-ancs.DataChan:
			fmt.Println(data.Original)
			fmt.Printf("%s app:%s title:%s subtitle:%s message:%s \n", time.Now(), data.AppIdentifier, data.Title, data.Subtitle, data.Message)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ancs

type Ancs struct {
	NotificationChan chan notificationInfo
	DataChan         chan dataInfo
	// contains filtered or unexported fields
}

Ancs structure

func NewAncs

func NewAncs(objectPath dbus.ObjectPath) (*Ancs, error)

func (*Ancs) GetNotificationAttributes

func (a *Ancs) GetNotificationAttributes(notification notificationInfo) error

GetNotificationAttributes 获取通知详情

func (*Ancs) SendToControl

func (a *Ancs) SendToControl(value []byte) error

SendToControl 发送信息至Control

func (*Ancs) StartNotify

func (a *Ancs) StartNotify() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL