I want to parse some messages from Messages. The chat messages are in some sort of attributed string. But I can’t work out how to get the data.
Screenshot of the data:
My code:
dim theDatabase as New SQLiteDatabase
dim theFolderitem as FolderItem = SpecialFolder.Desktop.Child("chat.db")
if not theFolderitem.Exists then Return
theDatabase.DatabaseFile = theFolderitem
try
theDatabase.Connect
catch err as DatabaseException
Return
end try
dim sql as String = "select attributedBody from message where guid = '50165FA0-396A-40E6-823E-DA59387FC808'"
dim Message as MemoryBlock
try
dim data as RowSet = theDatabase.SelectSQL(sql)
Message = data.Column("attributedBody").BlobValue
catch Err as DatabaseException
Return
end try
dim temp as new NSAttributedStringMBS
if temp.initWithString(Message) then
MessageBox(temp.Text)
end if
This contains the binary data:
INSERT INTO “message_test” (“attributedBody”) VALUES
( X’040b73747265616d747970656481e803840140848484124e5341747472696275746564537472696e67008484084e534f626a656374008592848484084e53537472696e67019484012b4054686579206d7573742062652073657175656e7469616c20746f20746865206d657373616765206e756d626572696e6720696e2065616368207468726561643f86840269490140928484840c4e5344696374696f6e617279009484016901928496961d5f5f6b494d4d657373616765506172744174747269627574654e616d658692848484084e534e756d626572008484074e5356616c7565009484012a84999900868686’ );