I am trying to send a value from my watch extension to my iPhone app. From various sources, it seems the best way is to use UserDefaults
, however I am getting some weird errors and i'm not able to retrieve the data I set into the userDefaults. I am using app groups and that has all been setup correctly. Here is my code
Watch Extension:
@IBAction func okBtnClicked() {
print("Ok")
let userDefaults = UserDefaults(suiteName: "group.iFindUserApp")
//userDefaults?.setValue("OK", forKey: "status")
userDefaults?.set(10, forKey: "testInt")
userDefaults?.synchronize()
}
And here is my viewcontroller in the iPhone app:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! FriendTableViewCell
//cell.configureCell(user: usersArr[indexPath.row])
let user = usersArr[indexPath.row]
// cell.nameLabel.text = "\(user.firstName) \(user.lastName)"
var defaults = UserDefaults(suiteName: "group.iFindUserApp")
var test = defaults?.value(forKey: "testInt")
cell.nameLabel.text = "\(test)"
return cell
}
The specific error I get is Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
I tried changing my groupName to TeamId.groupName
, and that just silenced the warning, but I was still unable to get a value (I just got nil).
Any help would be greatly appreciated!