Browse Source

Make getEmbeddedServerEntries optional

mirokuratczyk 5 years ago
parent
commit
99249f9956

+ 6 - 6
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.h

@@ -133,6 +133,12 @@ typedef NS_ENUM(NSInteger, PsiphonConnectionState)
  */
 - (id _Nullable)getPsiphonConfig;
 
+//
+// Optional delegate methods. Note that some of these are probably necessary for
+// for a functioning app to implement, for example `onConnected`.
+//
+@optional
+
 /*!
  Called when the tunnel is starting to get the initial server entries (typically embedded in the app) that will be used to bootstrap the Psiphon tunnel connection. This value is in a particular format and will be supplied by Psiphon Inc.
  If getEmbeddedServerEntriesPath is also implemented, it will take precedence over this method, unless getEmbeddedServerEntriesPath returns NULL or an empty string.
@@ -140,12 +146,6 @@ typedef NS_ENUM(NSInteger, PsiphonConnectionState)
  */
 - (NSString * _Nullable)getEmbeddedServerEntries;
 
-//
-// Optional delegate methods. Note that some of these are probably necessary for
-// for a functioning app to implement, for example `onConnected`.
-//
-@optional
-
 /*!
   Called when the tunnel is starting to get the initial server entries (typically embedded in the app) that will be used to bootstrap the Psiphon tunnel connection. This value is in a particular format and will be supplied by Psiphon Inc.
   If this method is implemented, it takes precedence over getEmbeddedServerEntries, and getEmbeddedServerEntries will not be called unless this method returns NULL or an empty string.

+ 10 - 8
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -303,14 +303,16 @@ typedef NS_ERROR_ENUM(PsiphonTunnelErrorDomain, PsiphonTunnelErrorCode) {
         // If getEmbeddedServerEntriesPath returns an empty string,
         // call getEmbeddedServerEntries
         if ([embeddedServerEntriesPath length] == 0) {
-            
-            dispatch_sync(self->callbackQueue, ^{
-                embeddedServerEntries = [self.tunneledAppDelegate getEmbeddedServerEntries];
-            });
-            
-            if (embeddedServerEntries == nil) {
-                [self logMessage:@"Error getting embedded server entries from delegate"];
-                return FALSE;
+            // getEmbeddedServerEntries is optional in the protocol
+            if ([self.tunneledAppDelegate respondsToSelector:@selector(getEmbeddedServerEntries)]) {
+                dispatch_sync(self->callbackQueue, ^{
+                    embeddedServerEntries = [self.tunneledAppDelegate getEmbeddedServerEntries];
+                });
+
+                if (embeddedServerEntries == nil) {
+                    [self logMessage:@"Error getting embedded server entries from delegate"];
+                    return FALSE;
+                }
             }
         }