XCUITest - How to access the app device token in XCUITest for triggering the push notification but without setting any UIView in app code? - xcuitest

Objective:
I want to retrieve the app device token for triggering a push notification in XCUITest. To perform the following tests
Tapping on the push notification
Asserting the push notification texts
Taking a screenshot of app's main screen once the push notification is received.
Limitation:
I should not create any UIView in the app code for retrieving the device token in my XCUITest.
Please suggest me if there is any other workaround considering the limitation.

Answered here (same asker, I assume): https://forums.developer.apple.com/thread/110361

Related

Is it OK to use flutter_hydrated for splash screen and authentication? Flutter

When the user downloads the app and opens it for the first time, a splash screen should show telling him to log in or other stuff. Then, every time the user re-open the app it should check for if the user is authenticated or not.
Can I do this with hydrated_bloc?
If you are using Firebase backend then on each launch of the app you will call firebaseInstance.currentUser() to check if authorized or not and this check will be through an event from the bloc when the app launches
If you are not using this backend then also on each launch of the app you will call some method to check if auth token (if exists) is still valid also through an event from the bloc
Now the HydratedBloc can save the previous state of the app but suppose you save the previous state and the user doesn't open the app until after token expires and you are using HydratedBloc so you will only rely on it to check the previously saved state (auth status) and not use the methods above so in this case you will login an UNAUTHENTICATED user into the app.
And if you say I will also do the above methods then what is the point of using this bloc in this case?
So looks like it is an overkill to use this bloc for this feature

Why chrome browser is changing endpoint frequently

I’m developing chrome push notification for my web site and doing the development in localhost (local machine) environment. Sending push notification is success with specific endpoint which I got when I subscribe the notification first time. I use same endpoint for all push messages.
Here sometime push notification got failed due to endpoint mismatch. When I see in chrome console (debugging mode) there was different endpoint.
Why chrome browser is changing endpoint? In this case how do we handle this scenario and update the new endpoint in the db?
sample endpoint:
https://android.googleapis.com/gcm/send/AWERdvfdfdsfdobRH4zlXGuyeuie3543uTBuP6air5dzZfltNa-FKF6K6S-9P5SdfbCbyvn9RdsfsdvU1XwSBwIrekjdK6_i4Cg-5rZAj8UvL1s-Bbr61yvvt_y2Hg9RdsyV
when i check next time, above endpoint got changed as like below
https://android.googleapis.com/gcm/send/reytryMkQwtY:YTUNMdsjjfhsdf349851VS6McDE7s_GITe_djsgfdkjghcdfdfgdftrkddfdsXiwX1vP_XclmDqrKPOAMJDfsYYXdhMX164694Q&ksdhfksdfhkjfhksdcndsk
Thank you.
The push notification endpoint is dependant on the service-worker. When a service-worker is unregistered and created again, the PushManager.getSubscription() method will indeed return null. You then need to call subscribe() again, which will return a new endpoint.
If you server tries to send a push notification to the first endpoint after the service-worker was unregistered, you will get a NotRegistered (for Chrome) or a Gone (for Firefox) error. So make sure to register the new endpoint as soon as the app loads or the device may become unreachable.
Note that this does not seem to affect service-worker updates.

How to trigger a "flyout, dialog, app bar or other inline element" if the phone receives a notification while the app is closed?

I'm working on a Windows Phone app that will receive push notifications and needs to show critical alerts to the user. As far as I can see there are 3 types of push notification:
Raw Notification - Raw notifications are used when your application is actually running on the device. This allows you to
update your interface “live” as the user is using it.
Toast Notification – This message will be received regardless of whether your application is running or not, but popping toast messages
while your app is running might be a little annoying. I’ll
demonstrate this example below. Toast WILL NOT also update your
application’s data. You still need to pass a Raw Notification to make
this happen.
Tile Notification – If your application is pinned to the user’s Start screen, you can update the Tile for your application. You can
change the background image, as well as an integer from 0-99.
source: http://www.jeffblankenburg.com/2010/10/19/31-days-of-windows-phone-day-19-push-notifications/
These each have different behaviours, but none lend themselves to critical notifications, where the user can be actively alerted to critical information.
Having read Guidelines for toast notifications on MSDN, it suggests
Don't use toast notifications to notify the user of something that
must be seen, such as a critical alert. To ensure that the user has
seen your message, notify them in the context of your app with a
Flyout, dialog, app bar, or other inline element.
So the question is, how can I trigger a "flyout, dialog, app bar or other inline element" if my app is closed and the phone receives a critical notification.
long story short: you can't enforce that your app opens on an incoming pns
But I think you've got the toast scenario wrong. A toast can be used to notify the user, if he taps it the app opens and you might react to that by the navigation uri (e.g.: ?fromToast=true).
If you receive a toast notification while your app is open the toast won't show. Toast Notifications only get displayed when your app isn't open. But you can react to an incoming toast notification (there's an event for that) to implement an behavior of your way (e.g.: flyout, msgbox, ...).
note: introduced with GDR3: The sound of the toast notification can now be changed (even made silent).

Handle push notification on background

I am developing an application in windows phone which having push notification facility. I am able to receive push message at device.
If Application is not running , I am getting message at home screen on the click of that msg it starts that application. I want to perform some task on the basis of that Push Notification Message. But i am not able to handle that event.
Please help me to handle that EVENT if application is running or application is in background or application is not running .
Thanking You,
Which type of notification are you sending? Based on your question I assume you are referring to toast notifications.
When do you want to perform the task - before or after the user clicks on the message? If the application is not running, you can only do it after clicking the message.

box.com api OAuth authentication

Either I'm dense, or the docs assume I already know what they're telling me, but I need some clarification on doing authentication for a box.com app. I really don't understand whate's going on. As I read it:
the app running on the user's machine sends a request to Box, including all the little secrets (Which aren't all that secret any more if the user knows how to read the code).
The user is directed to the Box login page, which then sends the user to my server (with no page specified) attaching an authentication code.
The app somehow magically gets that code back from my server and sends a request to Box for the access token.
Box sends the access token to my server?
The app again magically gets the access token from my server and sends its APT requests.
Obviously I got lost somewhere.
And, why do I have to have a server involved in the process? The article on making a JavaScript app refers to a direct request for a token. Is there documentation on that somewhere?
You register your application on Box
After registration you receive clientId and clientSecret once on Box website
You hardcode your credentials somewhere in your application
First time your application needs to access Box API it should redirect user to https://www.box.com/api/oauth2/authorize, specifying your clientId, clientSecret and redirectURI as parameters. About redirectURI see below.
The box.com website opens. User enters his own credentials in the web form on box.com
User allows your application to access his files via API on the box.com website
Box redirects user back to you application using redirectURI specified before. One of the parameters to this request is "code". This is a very short-lived (30 seconds) access code that is only aligable for obtaining real access token.
During next 30 seconds your application should make another call to Box API to next URL: https://www.box.com/api/oauth2/token, specifying the previously obtained code. If everything was correct, your application receives an access_token, a refresh_token and "expires" values.
Now your application can make requests to Box API, specifying access_token every time
access_token expires in number of seconds, specified in "expires" field. It should be about 3600 seconds or 1 hour. Each time your application sees that access_token has expired, it should make another request to Box with the refresh_token and obtain a fresh access_token for another 1 hour.
refresh_token itself expires in 14 days
Note: if you develop a desktop application, then you should open browser for user on the step 4, redirectURI should be something like http://127.0.0.1:8080/Callback and you should run a small webserver just to catch the redirect with the code as in step 7.
Box requires that you specify a redirect_uri in your application's profile, and it must be an HTTPS URL.
As a result, it is not possible to use box with what google's oauth2 documentation calls "Client Side" or "Installed" applications, only "Web Server Applications" are allowed. Web Server applications do not have the secret leaking problem, because only the server knows the secret. You can pass the access token from your server to javascript on the client after
the oauth transaction is complete, if you want the client to make api requests directly.
In your question you are not totally clear in what you are actually trying to produce.
I however suspect that you are trying to write a client application what needs to authenticate to box using the OAUTH2 solution they have delivered in API V2.
If this is for an IPhone for example BOX has a great example of how to handle it.
In a WinForm application you would need to capture the resulting code sent back by box in the browser1.isnavigating event.
Windows console application you register a custom URI registration to collect the code.
Neither of these need to be registered in the API developers Application on box as you would pass the redirect required in the request to box.
If this does not point you in the right direction and your writing a .NET app then post again and I will try to clarify a little more.
Box requires some form user interaction which is short sighted in my opinion but try a web service that simulates a user interaction which then you can save/pass the token to your application to sync up with the Box "Cloud".