0

I have implemented the built in twitter API, and everything is working great, however I am trying to decide how best to persist a twitter account between sessions when a user has multiple twitter accounts set up.

If I only receive a single ACAccount using -[ACAccountStore accountsWithAccountType:], this it's easy... I simply use that one. If, however, there are multiple ACAccounts I don't want to be asking them every time the enter the app which one to use.

The way I see it so far, my options are:

  1. Serialize the ACAccount object using NSKeyedArchiver (this would be the ideal, if it is possible)

  2. Bug the user every time (don't want to do this)

  3. Store only the username of the selected ACAccount, then in the next session compare the username in each account within the ACAccountStore, and select that account (although for some reason this seems like an inelegant workaround).

Many thanks in advance!

Karl White
  • 497
  • 1
  • 5
  • 13
  • 1
    option (3) seems like the safest option. Serializing the ACAccount object in it's entirety is a bit like overkill. The only time you would ask following that is if they wish to change, or their twitter account name changes. – Anya Shenanigans Feb 16 '13 at 20:31
  • Thanks Petesh! Yeah, I've gone with #3 and it seems to work pretty solidly. I just didn't like the idea of relying solely on the username, but it works so I guess I'm happy. – Karl White Feb 17 '13 at 07:11

1 Answers1

4

ACAccount has a property named identifier to uniquely identify a single account. The type of that property is an NSString so you can persist its value easily with either NSUserDefaults or NSCoding (or whatever other persistence solution you use). When you want to retrieve the account that belongs to this identifier, you just use the method -[ACAccountStore accountWithIdentifier:] and pass the identifier as the parameter.

Manuel Binna
  • 1,225
  • 2
  • 14
  • 23