Hololens 2 / MRTK / Unity / Asking for permissions programmatically - unity3d

Is it possible to check if app has permissions and if don't ask for permissions programmatically on Hololens 2?
In manifest permissions are already declared by sometimes if you miss the permission popup or click on NO by mistake the app doesn't ask for permission never again.
Unity 2020.3.13f1
MRTK 2.7.3
- Update -
I asked for this feature here:
https://github.com/microsoft/MixedRealityToolkit-Unity/issues/10675
Please support the request!

To check Microphone and Camera permissions on HoloLens 2, we can take advantage of WinRT API MediaCapture. If the app does not have Microphone and Camera permissions, when calling the InitializeAsync method, it will throw a UnauthorizedAccessException.
If we got this exception, there is no way to re-ask for permission programmatically. We should let the user to grant us the required permissions again in Settings with using the ms-settings:appsfeatures-app URI, which can open the advanced settings page for our app.
#if ENABLE_WINMD_SUPPORT
using (MediaCapture mediaCapture = new MediaCapture())
try
{
await mediaCapture.InitializeAsync();
}
catch (UnauthorizedAccessException)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:appsfeatures-app"));
}
#endif
Another way to check the permissions would be using AppCapability Class. CheckAccess method will return the access status. If the status is DeniedByUser, we will still need to open the advanced settings page for our app using the ms-settings:appsfeatures-app URI and let the user to grant us the required permissions.

Related

How to access calendar in MacOS screensaver?

Is it possible to access calendar events in screen saver? I am able to request permission in the application. But some API is not prompting in the case of the screensaver.
I didn't find any documentation around it.
I used the following code to requesting calendar events:
func requestPermissionForCalendar()
{
var eventStore = EKEventStore()
eventStore.requestAccess(to: EKEntityType.event) { granted, error in
if granted{
print("Permission granted")
}else{
print("The app is not permitted to access reminders, make sure to grant permission in the settings and try again")
}
}
}
Couple of things, first, a screen saver is completely passive in macOS. Any prompt for anything will be disregarded when it's running fullscreen, as a screensaver.
In general, the proper way to do this with a screensaver is to ask for permission in the configurationSheet (the screen saver options). The user will get prompted there, and can allow or deny you. I do use this for example to request the user location.
Once allowed in System Preferences, your screensaver when running in screensaver mode will get access. I suggest you test your code first in the configuration sheet as this is much easier.
Additional note, ScreenSavers on macOS since Catalina are sandboxed by an application extension provided by Apple, and that extension has a limited list of entitlements (see a list here https://github.com/glouel/ScreenSaverMinimal).
I'm not particularly familiar with EKEventStore, but if it requires a specific entitlement to make it work, you'll be stuck as you can't add any entitlement yourself, everything depends on legacyScreenSaver.appex.

Azure mobile facebook authentication with iPhone HTML5 in app (full screen) mode

I have an HTML5 application that uses Azure mobile services authentication to login (straight from the example code...provided below). It works fine in all desktop browsers and iPhone 5 in Safari. But from app / full screen mode, it does nothing (doesn't ask for permission to show a popup window like it does in safari and no popup windows shows up) and I can wait forever and nothing happens. If I invoke it a second time, it gives an error saying "Error: Unexpected failure"...perhaps because the 1st attempt is still running? Any help/insight is appreciated.
client.login ("facebook").done(function (results) {
alert("You are now logged in as: " + results.userId);
}, function (err) {
alert("Error: " + err);
});
edited update with more info and 2 potential ideas*
I did some more research and found a site that uses an approach that overcomes this problem and also solves two other side effects with the current Azure mobile approach to authentication. I think the Azure mobile team might be looking to do something similar because there are some hints of other authentication options in the code (although difficult to read and be sure because the minimized code is obsfucated). It might be just a matter of activating these in the code...
The "solution":
Go to http://m.bcwars.com/ and click on the Facebook login. You'll see it works perfectly in iPhone Safari in "app mode" becuase instead of doing a popup, it simply stays in the current browser window.
This approach solves two other problems with the current Azure mobile approach. First, the popup gets interpreted by most browsers as a potential ad and is either blocked automatically (desktop Chrome) ... and the user doesn't know why it's not working...or gives a warning which the user has to approve (iPhone Safari in "browser mode") which is a hassle. And if the user has a popup blocker, it gets more difficult and even more potential for the user not getting it to work properly. The bcwars.com method doesn't have this problem.
Second, in iPhone Safari, when the popup window auto closes, the original page doesn't get focus if there are other browser windows open in Safari. Instead, it's in the smaller/slide mode so they can choose which one to show. If this happens, the user has to go through one more sttep...click on the browser window to activate it and give it focus..again more of a pain and more potential for them to mess up and not do it correctly and need help. The m.bcwars.com doesn't have this problem.
Azure options:
Looking at the Azure mobile code it looks like may already have the solution. I can't read it easliy becuase it's minified/obsfucated, but it seems to have 4 options (including iFrame, etc.) for invoking the authentication, and only 1 (the "less ideal one" of a popup) is being used. An easy solution would be to set a property to allow one of the alternate authentications to work. But I can't read it well enough to figure it out. Another would be to hack the code (temporarily until a fix is put up by Microsoft).
Could I get some help there perhaps?
You can implement an authentication flow with Facebook that doesn't use a popup. The basic idea is to use the 'Web Flow' for doing the login, and once the window return from the login, use the access token to login the user in to Azure Mobile Services.
The Facebook documentation for doing this is here:
https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/#step2
Some code samples to make it easier for you.
You would start by something like this:
(Remember to replace YOUR_APP_ID and YOUR_URL with something relevant to your site.
function logIn() {
window.location.replace('https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=http%3A%2F%2FYOUR_URL&response_type=token')
}
This redirects the window to the Facebook page for the user to log in and authorize your app. When the user is done, Facebook will redirect the user back to YOUR_URL given above.
There you can handle the redirect and do the Mobile Services Login with something like this:
function handleLoginResponse() {
var frag = $.deparam.fragment();
if (frag.hasOwnProperty("access_token")) {
client.login("facebook", { access_token: frag.access_token }).then(function () {
// you're logged in
}, function (error) {
alert(error);
});
}
}
In here you parse the access token you get as a URL fragment and pass it as argument to the login call you make to Azure Mobile Services.
This code depends on the jquery BBQ plugin to handle the URL fragment easily.
Hope this solves your problem!

Why can't users can't access my Facebook canvas app?

I have developed a canvas app. I can access the app through Facebook, but others can't see it and stuck in this page. The app is live.
ASP.NET MVC 4.
My permissions.vbhtml: (if you want other file please tell me)
#Imports Microsoft.AspNet.Mvc.Facebook
#ModelType FacebookRedirectContext
#Code
ViewData("Title") = "Required Permissions"
End Code
#If Model.RequiredPermissions.Length > 0
#<h3>You need to grant the following permission(s) on Facebook to view this
page:</h3>
#<ul>
#For Each permission in Model.RequiredPermissions
#<li>#permission</li>
Next
</ul>
#<a class="buttonLink" href="#Html.Raw(Model.RedirectUrl)" target="_top">Authorize
this application</a>
End If
please check that the sandbox mode is disabled or not in your app settings. If its enabled then only an admin can see that. Make it disabled so other users also view your app.

facebook login give me already authorized this app without automatic returning to the app

My app should implement login with facebook but I have noticed that every time I want to login the facebook tell me you are already authorize this app , the question if I already authorized the app the facebook should return automatically without pressing the okey button as I saw in other applications ?
see the attached image
I fixed my problem by doing the following steps :
1- login to your facebook as admin to your app.
2- go to https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/summary.
3- go to settings > basic > Native IOS app
4- set the Configured for iOS SSO: to enabled
In iOS/Android the FBAccessToken's expiration time is up to 60 days. When you do FBLogin in your app you get the access token. once you get the token you should not do login again(otherwise you will be prompted already authorized this app since your app has already been given an access token earlier which is not expired ). You should reuse the unexpired access token.
Like this :
if FBSDKAccessToken.currentAccessToken() != nil {
print(FBSDKAccessToken.currentAccessToken().userID)
print(currentAccessToken().tokenString)
//OR call the *FBGraphRequest*
}
Note: for in-App browser login (SVC: Safari View Controller)
see more:
https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9/
and
https://developers.facebook.com/docs/reference/ios/4.9/class/FBSDKLoginManager/
You need to make sure that your app has the proper URL Prefix in your Build Settings. Also make sure that the URL Prefix matches your Facebook ID/URL Prefix in the Facebook developer app.
Edit: Your issue is probably that the access_token is expiring so it's have to re-ask for permissions.
This will happen if your application did not request offline_access permissions. In the newer SDK offline_access is deprecated and you now have to extend the access_token.
See this link: https://developers.facebook.com/docs/mobile/ios/build/#extend_token
As this Question is already answered , but i would like to add another helpful answer for Swift 3.0 :
While using FB Login in Swift , i having issue and i previously did this way:
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .systemAccount
As this uses , System account to check user is authorized for login or not . Unless you logout and login through different user , application shows same "Already authorized" message in place of Fresh login . So i used this way and this trick does the work :
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .web.
This show Login Screen after logout.
Hope this helps to solve this issue.
Feel free to comment . Thanks.
You should check if there is a current session before logging in with FBSDKLoginManager. Do not use [loginManager logout] before logging in.
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(#"Token is available : %#",[[FBSDKAccessToken currentAccessToken]tokenString]);
// Now get details using graphpath.
} else {
// login with permissions using FBSDKLoginManager and get details using graphpath in completion
}
There is a open bug at facebook.com
https://developers.facebook.com/bugs/190389531089978
But the bug only appears at android, ios works fine.
(btw. same behavior in the foursquare and spotify android app - check it out)
Run your iOS FB application into device not simulator it works fine, and didn't shows the already authorized screen.
Thank you.

BlackBerry Facebook jar file in eclipse

I know this might sound a very basic question but I am having an issue in using Facebook SDK for Blackberry. I have downloaded the latest one 0.8.25. I have imported them in my eclipse and they are present in the referenced libraries. I have a game app where I want the users to login using their facebook account. Which class contains the code for logging in? Are the jar files implementable or they are just for reference? I have read forums posts where users say that they executed Strawberry program but I can no where find any executable source code. Kindly please let me know how do I create a login page for BlackBerry using its SDK. I did go through another link of Sample Code here!
Let me know which class has login code or how do i use the SDK
At the very basic least, you need to get an instance of the Facebook object and call getCurrentUser(). So, for example:
String[] permissions = new String[] { Facebook.Permissions.ALL_PERMISSIONS };
Facebook fb = Facebook.getInstance(new ApplicationSettings(myNextUrl, myAppId, myAppSecret, permissions));
User fbUser = fb.getCurrentUser();
The code in the library will handle all of the details like getting the user to login to facebook account and accept the requested permissions and so on. You'll want to wrap that all in a try/except to catch FacebookException for error conditions (e.g. user refuses your request).