IMessageDataKit
Store custom data as key-value pairs in MSMessage objects.
Install / Use
/learn @sahin/IMessageDataKitREADME
Store custom data as key-value pairs in MSMessage objects.
Contents
Requirements
- iOS 10+
- Swift 3
- Messages.framework
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate iMessageDataKit into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'iMessageDataKit'
Then, run the following command in Terminal (from your project's root folder):
$ pod install
Manual
Drag & drop Source folder into your Xcode project.
Usage
iMessageDataKit extension methods enable you to use an MSMessage object as a dictionary-like key-value store. You can set/get Int, Bool, Float, Double, String and Array values. Arrays should contain objects that conform to LosslessStringConvertible protocol.
Quick Start
import Messages
import iMessageDataKit
class MessagesViewController: MSMessagesAppViewController {
// ...
func sendMessage() {
let layout = MSMessageTemplateLayout()
layout.caption = "A message with custom data."
let message: MSMessage = MSMessage()
message.layout = layout
//
// set custom data
//
message.md.set(value: 7, forKey: "user_id")
message.md.set(value: Int(NSDate().timeIntervalSince1970), forKey: "timestamp")
message.md.set(value: true, forKey: "is_okay")
message.md.set(value: "john", forKey: "username")
message.md.set(values: ["happy", "joy", "smile"], forKey: "tags")
message.md.set(values: [7.3, 5.2], forKey: "dimensions")
//
// send or insert message to activeConversation ...
//
}
override func didSelect(_ message: MSMessage, conversation: MSConversation) {
//
// access selected message's custom data
//
if let userId = message.md.integer(forKey: "user_id") {
// do sth with userId
}
if let timestamp = message.md.integer(forKey: "timestamp") {
// do sth with timestamp
}
if let isOkay = message.md.bool(forKey: "is_okay") {
// do sth with isOkay
}
if let username = message.md.string(forKey: "username") {
// do sth with username
}
if let tags = message.md.values(forKey: "tags") {
// do sth with tags array
}
if let dimensions = message.md.values(forKey: "dimensions") {
// do sth with dimensions array
}
}
// ...
}
How it works
iMessageDataKit encodes/decodes data as JSON and utilizes url property of MSMessage class to store encoded JSON string as a querystring.
Resources
Idea
- Sahin Boydas (@sahinboydas)
Author
- Ahmet Ardal (@ardalahmet)
License
iMessageDataKit is released under the MIT license. See LICENSE for details or visit http://www.apache.org/licenses/LICENSE-2.0 for more information.
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
