ParseLiveQuery
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public final class ParseLiveQuery : NSObject
The ParseLiveQuery
class enables two-way communication to a Parse Live Query
Server.
In most cases, you should not call this class directly as a LiveQuery can be indirectly
created from Query
using:
// If "Message" is a "ParseObject"
let myQuery = Message.query("from" == "parse")
guard let subscription = myQuery.subscribe else {
"Error subscribing..."
return
}
subscription.handleSubscribe { subscribedQuery, isNew in
//Handle the subscription however you like.
if isNew {
print("Successfully subscribed to new query \(subscribedQuery)")
} else {
print("Successfully updated subscription to new query \(subscribedQuery)")
}
}
The above creates a ParseLiveQuery
using either the liveQueryServerURL
(if it has been set)
or serverURL
when using ParseSwift.initialize
. All additional queries will be
created in the same way. The times you will want to initialize a new ParseLiveQuery
instance
are: 1) If you want to become a ParseLiveQueryDelegate
to respond to authentification challenges
and/or receive metrics and error messages for a ParseLiveQuery
client.
2) You have specific LiveQueries that need to subscribe to a server that have a different url than
the default. 3) You want to change the default url for all LiveQuery connections when the app is already
running. Initializing new instances will create a new task/connection to the ParseLiveQuery
server.
When an instance is deinitialized it will automatically close it’s connection gracefully.
-
Have all
ParseLiveQuery
authentication challenges delegated to you. There can only be one of these for allParseLiveQuery
connections. The default is to delegate to theauthentication
call block passed toParseSwift.initialize
or if there is not one, delegate to the OS. Conforms toParseLiveQueryDelegate
.Declaration
Swift
public weak var authenticationDelegate: ParseLiveQueryDelegate? { get set }
-
Have
ParseLiveQuery
connection metrics, errors, etc delegated to you. A delegate can be assigned to individual connections. Conforms toParseLiveQueryDelegate
.Declaration
Swift
public weak var receiveDelegate: ParseLiveQueryDelegate?
-
True if the connection to the url is up and available. False otherwise.
Declaration
Swift
public internal(set) var isSocketEstablished: Bool { get set }
-
True if this client is connected. False otherwise.
Declaration
Swift
public internal(set) var isConnected: Bool { get set }
-
True if this client is connecting. False otherwise.
Declaration
Swift
public internal(set) var isConnecting: Bool { get set }
-
Declaration
Swift
public init(serverURL: URL? = nil, isDefault: Bool = false, notificationQueue: DispatchQueue = .main) throws
Parameters
serverURL
The URL of the
ParseLiveQuery
Server to connect to. Defaults tonil
in which case, it will use the URL passed inParseSwift.initialize(...liveQueryServerURL: URL)
. If no URL was passed, this assumes the current Parse Server URL is also the LiveQuery server.isDefault
Set this
ParseLiveQuery
client as the default client for all LiveQuery connections. Defaults value of false.notificationQueue
The queue to return to for all delegate notifications. Default value of .main.
-
Set a specific ParseLiveQuery client to be the default for all
ParseLiveQuery
connections.Declaration
Swift
public class func setDefault(_ client: ParseLiveQuery)
Parameters
client
The client to set as the default.
-
Get the default
ParseLiveQuery
client for all LiveQuery connections.Declaration
Swift
public class func getDefault() -> ParseLiveQuery?
-
Check if a query has an active subscription on this
ParseLiveQuery
client.Declaration
Swift
public func isSubscribed<T>(_ query: Query<T>) throws -> Bool where T : ParseObject
Parameters
query
Query to verify.
-
Check if a query has a pending subscription on this
ParseLiveQuery
client.Declaration
Swift
public func isPendingSubscription<T>(_ query: Query<T>) throws -> Bool where T : ParseObject
Parameters
query
Query to verify.
-
Remove a pending subscription on this
ParseLiveQuery
client.Declaration
Swift
public func removePendingSubscription<T>(_ query: Query<T>) throws where T : ParseObject
Parameters
query
Query to remove.
-
Manually establish a connection to the
ParseLiveQuery
Server.Declaration
Swift
public func open(isUserWantsToConnect: Bool = true, completion: @escaping (Error?) -> Void)
Parameters
isUserWantsToConnect
Specifies if the user is calling this function. Defaults to
true
.completion
Returns
nil
if successful, anError
otherwise. -
Manually disconnect from the
ParseLiveQuery
Server.Declaration
Swift
public func close()