Skip to content

Commit

Permalink
[cloud_firestore] ios ceck for nil snapshot in cloud_firestore error …
Browse files Browse the repository at this point in the history
…handling instead of checking for non-nil error (flutter#1339)

* Check for nil snapshot in cloud_firestore error handling instead of checking for non-nil error
  • Loading branch information
collinjackson authored Mar 14, 2019
1 parent f30ef67 commit 228b40f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.6

* On iOS, update null checking to match the recommended pattern usage in the Firebase documentation.
* Fixes a case where snapshot errors might result in plugin crash.

## 0.9.5+2

* Fixing PlatformException(Error 0, null, null) which happened when a successful operation was performed.
Expand Down
11 changes: 7 additions & 4 deletions packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
FIRDocumentReference *document = getDocumentReference(call.arguments);
[document getDocumentWithCompletion:^(FIRDocumentSnapshot *_Nullable snapshot,
NSError *_Nullable error) {
if (error) {
if (snapshot == nil) {
result(getFlutterError(error));
} else {
result(@{
Expand All @@ -411,7 +411,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}
id<FIRListenerRegistration> listener = [query
addSnapshotListener:^(FIRQuerySnapshot *_Nullable snapshot, NSError *_Nullable error) {
if (error) {
if (snapshot == nil) {
result(getFlutterError(error));
return;
}
Expand All @@ -426,7 +426,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
FIRDocumentReference *document = getDocumentReference(call.arguments);
id<FIRListenerRegistration> listener =
[document addSnapshotListener:^(FIRDocumentSnapshot *snapshot, NSError *_Nullable error) {
if (error) {
if (snapshot == nil) {
result(getFlutterError(error));
return;
}
Expand All @@ -450,7 +450,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}
[query getDocumentsWithCompletion:^(FIRQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error) {
if (error) result(getFlutterError(error));
if (snapshot != nil) {
result(getFlutterError(error));
return;
}
result(parseQuerySnapshot(snapshot));
}];
} else if ([@"Query#removeListener" isEqualToString:call.method]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
version: 0.9.5+2
version: 0.9.6

flutter:
plugin:
Expand Down

0 comments on commit 228b40f

Please sign in to comment.