user2815661
user2815661

Reputation: 51

passing data between sirikit intent handler and the app

ios does not let the containing app and the contained extensions to share a common container, so UserDefaults is the proposed solution.

I have tried using UserDefaults with sirikit intent handler assuming the handler behaves as an extension as follows :

inside IntentHandler.swift

let shared = UserDefaults(suiteName:XXXXXXXX.group...)
shared?.set("saved value 1", forKey: "key1")
shared?.set("saved value 2", forKey: "key2")
shared?.set("saved value 3", forKey: "key3")

inside ViewController.swift in viewDidLoad

let shared = UserDefaults(suiteName:XXXXXXXX.group...)
if let temp1 = shared?.string(forKey:"key1")
{
contentLabel.text = temp1
}
if let value = shared?.string(forKey: "key2")
{
valueLabel.text = value
} 
if let key = shared?.string(forKey: "key3")
{
keyLabel.text = key
}

i can see the strings corresponding to key1 and key2 on my ipad screen but not for key3, peppering the code with synchronizes does not help.

here are my questions :

1) are sirikit handlers different from other extensions? if yes how to pass data to my app? if not am i using UserDefaults incorrectly?

2) is there a better way to handle IPC between the app and its extensions where i just need to pass simple string messages between them.

using swift 3.0 and xcode 8.2.1

Upvotes: 5

Views: 2934

Answers (2)

Florian
Florian

Reputation: 236

Check that you have the App Group enabled for all targets you want to access the group from. Check in project -> your target -> capabilities under "App Groups".

Upvotes: 1

Harman Khurana
Harman Khurana

Reputation: 39

There's something called MMWomhole. It will definitely do the work.

Upvotes: 0

Related Questions