Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit a9d8159

Browse files
author
Rad Azzouz
committed
Merge pull request #120 from AgileBits/bugfix/fix-crash-when-the-extension-is-called-before-the-webview-is-fully-loaded
Fixed crash when the 1Password extension is shown before the web view is fully loaded.
2 parents fc2806d + 12a75f9 commit a9d8159

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

OnePasswordExtension.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
NSInteger const AppExtensionErrorCodeCollectFieldsScriptFailed = 4;
4747
NSInteger const AppExtensionErrorCodeFillFieldsScriptFailed = 5;
4848
NSInteger const AppExtensionErrorCodeUnexpectedData = 6;
49+
NSInteger const AppExtensionErrorCodeFailedToObtainURLStringFromWebView = 7;
4950

5051

5152
@implementation OnePasswordExtension
@@ -352,6 +353,12 @@ + (NSError *)failedToLoadItemProviderDataErrorWithUnderlyingError:(NSError *)und
352353
return [[NSError alloc] initWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToLoadItemProviderData userInfo:userInfo];
353354
}
354355

356+
+ (NSError *)failedToObtainURLStringFromWebViewError {
357+
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedString(@"Failed to obtain URL String from web view. The web view must be loaded completely when calling the 1Password Extension", @"1Password Extension Error Message") };
358+
return [NSError errorWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToObtainURLStringFromWebView userInfo:userInfo];
359+
}
360+
361+
355362
#pragma mark - App Extension ItemProvider Callback
356363

357364
#ifdef __IPHONE_8_0
@@ -433,6 +440,12 @@ - (void)fillLoginIntoUIWebView:(UIWebView *)webView webViewController:(UIViewCon
433440
}
434441

435442
- (void)findLoginIn1PasswordWithURLString:URLString collectedPageDetails:(NSString *)collectedPageDetails forWebViewController:(UIViewController *)forViewController sender:(id)sender withWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion {
443+
if ([URLString length] == 0) {
444+
NSError *URLStringError = [OnePasswordExtension failedToObtainURLStringFromWebViewError];
445+
NSLog(@"Failed to findLoginIn1PasswordWithURLString: %@", URLStringError);
446+
completion(NO, URLStringError);
447+
}
448+
436449
NSDictionary *item = @{ AppExtensionVersionNumberKey : VERSION_NUMBER, AppExtensionURLStringKey : URLString, AppExtensionWebViewPageDetails : collectedPageDetails };
437450

438451
__weak __typeof__ (self) miniMe = self;

0 commit comments

Comments
 (0)