2009-10-08 21 views

risposta

19

Utilizzare il portachiavi Apple.

+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error; 

+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error; 

The first method allows you to request the password associated with an existing username for a particular service name (I’ve just been using the name of my app as a service name). The second allows you to store a username/password/service name combo, and allows you to specify whether or not the appropriate keychain item should be updated with the provided password if an existing one is found that matches the username and service name pair. The last parameter of each is a reference to an NSError object which will contain lower level error information if something goes wrong (and be nil if it does not).

Per ulteriori informazioni consultare his blog

+0

è la password restituita in testo semplice? – pxl

+0

quando aggiungo quella classe per il mio progetto ho Prendi un gruppo di strani errori, come "_kSecAttrAccount", fa riferimento a: _kSecAttrAccount $ non_lazy_ptr in SFHFKeychainUtils.o "_SecItemDelete", fa riferimento a: + [SFHFKeychainUtils deleteItemForUsername: andServiceName: errore: ] in SFHFKeychainUtils.o "_kSecReturnAttributes", fa riferimento a: _kSecReturnAttributes $ non_lazy_ptr in SFHFKeychainUtils.o "_kSecClass", fa riferimento a: _kSecClass $ non_lazy_ptr in SFHFKeychainUtils.o "_kSecClassGenericPassword", fa riferimento a: _kSecClassGenericPassword $ non_lazy_ptr in SFHFKeychainUtils.o – Jason

+0

Qual è la procedura migliore per memorizzare il valore del nome utente? C'è un modo per trovare i nomi utente, dato solo il ServiceName? – cksubs

5

Il keychain è quello che state cercando.

+2

Questo link è per il portachiavi di Mac OS X. Ecco il link per la versione per iPhone (sono leggermente diversi): http://developer.apple.com/IPhone/library/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html –

+0

Oh, grazie. Risolto il problema. –

3

Utilizzare il portachiavi, qui è some code per renderlo molto facile. Funziona sul dispositivo e sul simulatore.

Problemi correlati