diff --git a/OnePasswordExtension.h b/OnePasswordExtension.h index 6213dde..e91d9b7 100644 --- a/OnePasswordExtension.h +++ b/OnePasswordExtension.h @@ -13,6 +13,8 @@ #import #endif +NS_ASSUME_NONNULL_BEGIN + // Login Dictionary keys - Used to get or set the properties of a 1Password Login #define AppExtensionURLStringKey @"url_string" #define AppExtensionUsernameKey @"username" @@ -85,7 +87,7 @@ @param error Reply parameter that is nil if the 1Password Extension has been successfully completed, or it contains error information about the completion failure. */ -- (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion; +- (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError *error))completion; /*! Create a new login within 1Password and allow the user to generate a new password before saving. @@ -108,7 +110,7 @@ @param error Reply parameter that is nil if the 1Password Extension has been successfully completed, or it contains error information about the completion failure. */ -- (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDictionary passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion; +- (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDictionary passwordGenerationOptions:(nullable NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError * __nullable error))completion; /*! Change the password for an existing login within 1Password. @@ -134,7 +136,7 @@ @param error Reply parameter that is nil if the 1Password Extension has been successfully completed, or it contains error information about the completion failure. */ -- (void)changePasswordForLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDict passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion; +- (void)changePasswordForLoginForURLString:(NSString *)URLString loginDetails:(nullable NSDictionary *)loginDetailsDict passwordGenerationOptions:(nullable NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError * __nullable error))completion; /*! Called from your web view controller, this method will show all the saved logins for the active page in the provided web @@ -154,7 +156,7 @@ @param error Reply parameter that is nil if the 1Password Extension has been successfully completed, or it contains error information about the completion failure. */ -- (void)fillItemIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(id)sender showOnlyLogins:(BOOL)yesOrNo completion:(void (^)(BOOL success, NSError *error))completion; +- (void)fillItemIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(nullable id)sender showOnlyLogins:(BOOL)yesOrNo completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion; /*! Called in the UIActivityViewController completion block to find out whether or not the user selected the 1Password Extension activity. @@ -162,7 +164,7 @@ @param the bundle identidier of the selected activity in the share sheet. @return YES if the selected activity is the 1Password extension, NO otherwise. */ -- (BOOL)isOnePasswordExtensionActivityType:(NSString *)activityType; +- (BOOL)isOnePasswordExtensionActivityType:(nullable NSString *)activityType; /*! The returned NSExtensionItem can be used to create your own UIActivityViewController. Use `isOnePasswordExtensionActivityType:` and `fillReturnedItems:intoWebView:completion:` in the activity view controller completion block to process the result. The completion block is guaranteed to be called on the main thread. @@ -173,7 +175,7 @@ @param error Reply parameter that is nil if the 1Password extension item has been successfully created, or it contains error information about the completion failure. */ -- (void)createExtensionItemForWebView:(id)webView completion:(void (^)(NSExtensionItem *extensionItem, NSError *error))completion; +- (void)createExtensionItemForWebView:(id)webView completion:(void (^)(NSExtensionItem * __nullable extensionItem, NSError * __nullable error))completion; /*! Method used in the UIActivityViewController completion block to fill information into a web view. @@ -185,11 +187,13 @@ @param error Reply parameter that is nil if the 1Password Extension has been successfully completed, or it contains error information about the completion failure. */ -- (void)fillReturnedItems:(NSArray *)returnedItems intoWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion; +- (void)fillReturnedItems:(NSArray *)returnedItems intoWebView:(id)webView completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion; /*! Deprecated in version 1.3. @see Use fillItemIntoWebView:forViewController:sender:showOnlyLogins:completion: instead */ -- (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(BOOL success, NSError *error))completion __attribute__((deprecated("Use fillItemIntoWebView:forViewController:sender:showOnlyLogins:completion: instead. Deprecated in version 1.3"))); +- (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion __attribute__((deprecated("Use fillItemIntoWebView:forViewController:sender:showOnlyLogins:completion: instead. Deprecated in version 1.3"))); @end + +NS_ASSUME_NONNULL_END diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 28707b4..00e1fd2 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -55,7 +55,7 @@ - (BOOL)isAppExtensionAvailable { #pragma mark - Native app Login -- (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion { +- (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError * __nullable error))completion { NSAssert(URLString != nil, @"URLString must not be nil"); NSAssert(viewController != nil, @"viewController must not be nil"); @@ -103,7 +103,7 @@ - (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewCon #pragma mark - New User Registration -- (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDictionary passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion { +- (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDictionary passwordGenerationOptions:(nullable NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError * __nullable error))completion { NSAssert(URLString != nil, @"URLString must not be nil"); NSAssert(loginDetailsDictionary != nil, @"loginDetailsDict must not be nil"); NSAssert(viewController != nil, @"viewController must not be nil"); @@ -159,7 +159,7 @@ - (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary #pragma mark - Change Password -- (void)changePasswordForLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDict passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion { +- (void)changePasswordForLoginForURLString:(NSString *)URLString loginDetails:(nullable NSDictionary *)loginDetailsDict passwordGenerationOptions:(nullable NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(NSDictionary * __nullable loginDictionary, NSError * __nullable error))completion { NSAssert(URLString != nil, @"URLString must not be nil"); NSAssert(viewController != nil, @"viewController must not be nil"); @@ -214,7 +214,7 @@ - (void)changePasswordForLoginForURLString:(NSString *)URLString loginDetails:(N #pragma mark - Web View filling Support -- (void)fillItemIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(id)sender showOnlyLogins:(BOOL)yesOrNo completion:(void (^)(BOOL success, NSError *error))completion { +- (void)fillItemIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(nullable id)sender showOnlyLogins:(BOOL)yesOrNo completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion { NSAssert(webView != nil, @"webView must not be nil"); NSAssert(viewController != nil, @"viewController must not be nil"); @@ -243,11 +243,11 @@ - (void)fillItemIntoWebView:(id)webView forViewController:(UIViewController *)vi #pragma mark - Support for custom UIActivityViewControllers -- (BOOL)isOnePasswordExtensionActivityType:(NSString *)activityType { +- (BOOL)isOnePasswordExtensionActivityType:(nullable NSString *)activityType { return [@"com.agilebits.onepassword-ios.extension" isEqualToString:activityType] || [@"com.agilebits.beta.onepassword-ios.extension" isEqualToString:activityType]; } -- (void)createExtensionItemForWebView:(id)webView completion:(void (^)(NSExtensionItem *extensionItem, NSError *error))completion { +- (void)createExtensionItemForWebView:(id)webView completion:(void (^)(NSExtensionItem * __nullable extensionItem, NSError * __nullable error))completion { NSAssert(webView != nil, @"webView must not be nil"); #ifdef __IPHONE_8_0 @@ -288,7 +288,9 @@ - (void)createExtensionItemForWebView:(id)webView completion:(void (^)(NSExtensi #endif } -- (void)fillReturnedItems:(NSArray *)returnedItems intoWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion { +- (void)fillReturnedItems:(NSArray *)returnedItems intoWebView:(id)webView completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion { + NSAssert(webView != nil, @"webView must not be nil"); + if (returnedItems.count == 0) { NSError *error = [OnePasswordExtension extensionCancelledByUserError]; if (completion) { @@ -667,7 +669,7 @@ + (NSError *)failedToObtainURLStringFromWebViewError { Deprecated in version 1.3. Use fillItemIntoWebView:forViewController:sender:showOnlyLogins:completion: instead */ -- (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(id)sender completion:(void (^)(BOOL success, NSError *error))completion { +- (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController sender:(nullable id)sender completion:(nullable void (^)(BOOL success, NSError * __nullable error))completion { [self fillItemIntoWebView:webView forViewController:viewController sender:sender showOnlyLogins:YES completion:completion]; }