The iOS App supports the 1Password plug-in

1Password is what I will not repeat here, do not understand, you can go to the official website to know about ~!

1Password can easily store our account password, and the generated account password is very complex, very high security. If our app also supports 1Password, it will undoubtedly be convenient for users and improve our app’s “bigger””

1Password development site on the GitHub, which describes more detailed, I also just read its readme, and then come to show off.

1. integrated 1Password requires three files

Picture set, header file, implementation file,

The iOS App supports the 1Password plug-in
integrates three files

2. edit URLScheme

Because of the need to jump in the iOS9 system, you need to configure URLScheme,
works in the plist file, add the LSApplicationQueriesSchemes array, and add a member named org-appextension-feature-password-management in the array can be

The iOS App supports the 1Password plug-in
plist file editing

3. increase the 1Password button

Add a button to the Xib. The icon has
on the 1Password.xcassets. This button is displayed when the 1Password service is displayed, otherwise it does not appear

Self.onePassBtn.hidden = = [[OnePasswordExtension, sharedExtension], isAppExtensionAvailable];

4. integrated 1Password needs to implement three functions

Below we can integrate 1Password, need to integrate the place has three: when registering the account number, when landing, changes the password

Registered account number: (save account number, password)
- (IBAction) saveLoginTo1Password: (ID sender) {NSDictionary *newLoginDetails = AppExtensionTitleKey: @{@ "XX client account" AppExtensionUsernameKey: self.nameLabel.text? "" AppExtensionPasswordKey:: @ self.passLabel.text @ AppExtensionNotesKey::? "" @ "in the XX client save"}; / / The password generation options are optional, but are very handy in case you have strict rules about password lengths, symbols and digits. NSDictionary * passwordGenerationOptions minimum password L / / The = @{ Ength can be 4 or more. @ AppExtensionGeneratedPasswordMinLengthKey: (6), maximum password length can / / The be 50 or less. @ AppExtensionGeneratedPasswordMaxLengthKey: (20), If the 1Password will / YES guarantee that the generated password will contain at least one digit (number between 0 and 9). Passing NO will not exclude digits from the generated password. AppExtensionGeneratedPasswordRequireDigitsKey: @ (YES), YES the 1Password will / If, guarantee That the generated password will contain at least one symbol (See the list bellow Passing NO with). Will exclude symbols from the generated password. @ AppExtensionGeneratedPasswordRequireSymbolsKey: (NO), Here are all the symbols available / in the the 1Password Password Generator: @#$%^& (*); / /! ". _-+=|[]{}'//; > / / The, /~`? String for AppExtensionGeneratedPasswordForbiddenCharactersKey should contain the symbols and characters that you wish 1Password to exclude from the generated password. AppExt EnsionGeneratedPasswordForbiddenCharactersKey: @ @#$%/lIO! "}; [[OnePasswordExtension sharedExtension] storeLoginForURLString:@ loginDetails:newLoginDetails passwordGenerationOptions:passwordGenerationOptions forViewController:" XX client "self sender:sender completion:^ (NSDictionary *loginDictionary, NSError *error) {if (loginDictionary.count = = 0) {if (error.code! = AppExtensionErrorCodeCancelledByUser) {NSLog (" Failed to use 1Password @ App Extension to save a new Login:% @ ", error) return;}}; self.nameLabel.text = loginDictionary[AppExtensionUsernameKey]; self.passLabel.text: @?" = loginDictio Nary[AppExtensionPasswordKey]: @? "/ / retrieve any additional fields that; were passed in newLoginDetails dictionary}];}

The principle is very simple, first of all to the user name and password, if the user before using 1Password to save the password, enter the account password has been good, it will directly into the 1Password, if there is no input into empty, regardless of whether it is empty, can continue to modify the account password in 1Password

Then the password restrictions are declared, such as the maximum and minimum length, whether to allow special characters, avoid characters, and so on

After the following method is executed, the block content is called

- (void) storeLoginForURLString: (nonnull * NSString) URLString loginDetails: (nullable NSDictionary * loginDetailsDictionary passwordGenerationOptions: (nullable) NSDictionary * passwordGenerationOptions (nonnull) forViewController: UIViewController * viewController sender: (nullable) id sender (nullable) completion: (void ^) (NSDictionary * __nullable loginDictionary NSError * __nullable error)) completion;

The first parameter, URLString, is the symbol of our application. It is usually a URL, but I find it possible to use a random string.

When the call is finished, it is bounced to 1Password

The iOS App supports the 1Password plug-in
pops up 1Password, and you can enter 1Password after clicking

Users edit the account password, click on the completion of the block account password input box will be re assigned

Login: (obtain account password)
- (IBAction) findLoginFrom1Password: (ID) sender [[OnePasswordExtension sharedExtension] {findLoginForURLString:@ "XX client" forViewController:self sender:sender completion:^ (NSDictionary *loginDictionary, NSError *error) {if (loginDictionary.count = = 0) {if (error.code! = AppExtensionErrorCodeCancelledByUser) {NSLog ("Error invoking 1Password App @ Extension for find login:, error}% @"); return; self.nameLabel.text = loginDictionary[} AppExtensionUsernameKey]; self.passLabel.text = loginDictionary[AppExtensionPasswordKey];}]};

Reading is the simplest, just bring into our URLString

Modify password:
- (IBAction) changePasswordIn1Password: (ID sender) {NSString *changedPassword = self.anewPassLabel.text? "NSString": @; *oldPassword = self.passLabel.text; NSDictionary: @? "" *loginDetails = AppExtensionTitleKey: "@{@ XX client account," used for the third / Optional schenario only AppExtensionPasswordKey: changedPassword, AppExtensionOldPasswordKey: oldPassword, AppExtensionNotesKey: @ XX client save "/ / Optional used for, the third schenario only The password generation}; / / options are optional, but are very handy in case you have Strict rules about password lengths, symbols and digits. NSDictionary *passwordGenerationOptions The minimum password length = @{/ / can be 4 or more. @ AppExtensionGeneratedPasswordMinLengthKey: (6), maximum password length can / / The be 50 or less. @ AppExtensionGeneratedPasswordMaxLengthKey: (20), If the 1Password will / YES guarantee that the generated password will contain at least one (digit number between 0 and 9) Passing NO will not. Exclude digits from the generated password. AppExtensionGeneratedPasswordRequireDigitsKey: @ (YES), If the 1Password will / YES guarantee that the generated password will contain at least one symbol (See the list bellow Passing NO with). Will exclude symbols from the generated password. @ AppExtensionGeneratedPasswordRequireSymbolsKey: (NO), Here are all the symbols available / in the the 1Password Password Generator: @#$%^& / /! (*) _-+=|[]{}'// ";. > / / The string for AppExtensionGeneratedPasswordFor /~`? BiddenCharactersKey should contain the symbols and characters that you wish 1Password to exclude from the generated password. AppExtensionGeneratedPasswordForbiddenCharactersKey: @ @#$%/lIO! "}; [[OnePasswordExtension sharedExtension] changePasswordForLoginForURLString:@ loginDetails:loginDetails passwordGenerationOptions:passwordGenerationOptions forViewController:self" XX client "sender:sender completion:^ (NSDictionary *loginDictionary, NSError *error) {if (loginDictionary.count = = 0) {if (error.code! = AppExtensionErrorCodeCancelledByUser) {NSLog (@" Error invoking 1Password App Extension for find lo Gin: ", error);% @ return}}; self.passLabel.text = loginDictionary[AppExtensionOldPasswordKey]; self.anewPassLabel.text = loginDictionary[AppExtensionPasswordKey];}]};

Similar to the preservation, first of all, the old, new password (but apparently the old password, no eggs, the old password is used after entering the 1Password, select the password of the account).
and then configure password restrictions, enter 1Password, set up later, in the finished block, modify the old, new password content, old fill in the last storage, the new fill just changed

So far, 1Password has been integrated.
you can run the Demo code on the official GitHub to see the effect.

PS:

I haven’t tried 1Password before, but I found a very good place, the time of registration, if you have a Xiaoming account, the password is 123456, I registered a Xiaoming, password is QWERTY, save after two Xiaoming 1Password account, and password into QWERTY, do not know is not a problem of Demo code. In short, the official Demo is the same, has not found the reason, ask for guidance