-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PushKit support #1458
PushKit support #1458
Conversation
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(120.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
timeoutBlock(); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giomfo Similar situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morozkin But Apple guideline says you have to call reportIncoming Call in pushKit Delegate otherwise application will crash.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
completionBlock(); | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giomfo We need to decide which value will be appropriate here and i think it'll be better to assign this value to a constant
@giomfo Maybe it also will be better to pause MXSession when we've ended with push handling? |
@giomfo wdyt? Also have a look at other scenarios |
If #1472 will look good to you, we will need to merge it with this PR |
The PR was merged even if some issues has been detected. See https://matrix.to/#/!dBmmlOkhBOeZNEAfDK:matrix.org/$1504019660293757xpuGS:matrix.org Step by step improvements will follow. |
To test PushKit notifications on your local machine change bundle id of the project to im.vector.pushtest. Perform changes in
initMatrixSession
to allow calling[accountManager prepareSessionForActiveAccounts]
even in background mode. Also you will need a pem certificate which can be provided to you by me or Dave. To send pushes i use Houston.Initially PushKit must be used only for VoIP notifications, but then it was decided to use it for all types of notifications in Riot. So the purpose of this is PR to provide this level of support.
The flow of registering for notifications didn't change a lot. There're new methods which replaced the old one. All of them belongs to
PKPushRegistryDelegate
protocol:pushRegistry:didUpdatePushCredentials:forType:
pushRegistry:didInvalidatePushTokenForType:
pushRegistry:didReceiveIncomingPushWithPayload:forType:
To be able to handle PushKit notifications we create a
PushRegistry
instance, set AppDelegate as its delegate and hold for entire life of the app.We subscribe for events from MXNotificationCenter instance of active MXSession when a new push is received. On arriving of each event an alert body string is created and then local notification is displayed.
Since we have a deal with network i add a delay for two cases:
pushNotificationHandlingTimeoutBlock
which is called when server sync takes a lot of time.pushNotificationHandlingCompletionBlock
is called with delay after push event has been successfully processed. I added delay here to support handling of series incoming pushes.Push1->Push1 has been handled->Schedule Push1 completion block->Push2->Cancel Push1 completion block->Wait for Push2 event...
I set a random constants for these delays, so i'm glad to hear your proposals.
The list of possible cases we can meet:
Receive push -> start listening for push events from server sync response -> schedule timeout block -> cancel timeout block -> handle push event -> schedule completion block -> execute completion block -> end
Receive push -> start listening for push events from server sync response -> schedule timeout block -> execute timeout block -> end
Receive push -> start listening for push events from server sync response -> schedule timeout block -> cancel timeout block -> handle push event -> schedule completion block -> receive new push -> cancel completion block -> schedule timeout block -> wait for new push event from server
Receive push -> start listening for push events from server sync response -> schedule timeout block -> new push -> cancel timeout block -> schedule new timeout block -> cancel timeout block -> handle push event (from 1st push) -> schedule completion block -> | WAITING TIME | ->
We have two ways to continue:
-> execute completion block (1st push event) -> end (2nd push event won't be handled) PROBLEM
-> cancel completion block -> receive new push event (from 2nd push) -> schedule new completion block -> end
If we won't receive any events before completion block of first push event would be called we will lose second push event.
Signed-off-by: Denis Morozov dmorozkn@gmail.com