private void handleAuthorizationError(NSError authorizationError) { NSDictionary unauthorizedAPIInfo = (NSDictionary)authorizationError.UserInfo.ObjectForKey(WTAuthorizationRequestManager.WTUnauthorizedAppleiOSSDKAPIsKey); NSMutableString detailedAuthorizationErrorLogMessage = (NSMutableString) new NSString("The following authorization states do not meet the requirements:").MutableCopy(); NSMutableString missingAuthorizations = (NSMutableString) new NSString("In order to use the Wikitude SDK, please grant access to the following:").MutableCopy(); foreach (NSString unauthorizedAPIKey in unauthorizedAPIInfo.Keys) { NSNumber unauthorizedAPIValue = (NSNumber)unauthorizedAPIInfo.ObjectForKey(unauthorizedAPIKey); detailedAuthorizationErrorLogMessage.Append(new NSString("\n")); detailedAuthorizationErrorLogMessage.Append(unauthorizedAPIKey); detailedAuthorizationErrorLogMessage.Append(new NSString(" = ")); detailedAuthorizationErrorLogMessage.Append(WTAuthorizationRequestManager.StringFromAuthorizationStatusForUnauthorizedAppleiOSSDKAPI(unauthorizedAPIValue.Int32Value, unauthorizedAPIKey)); missingAuthorizations.Append(new NSString("\n *")); missingAuthorizations.Append(WTAuthorizationRequestManager.HumanReadableDescriptionForUnauthorizedAppleiOSSDKAPI(unauthorizedAPIKey)); } Console.WriteLine(detailedAuthorizationErrorLogMessage); UIAlertController settingsAlertController = UIAlertController.Create("Required API authorizations missing", missingAuthorizations, UIAlertControllerStyle.Alert); settingsAlertController.AddAction(UIAlertAction.Create("Open Settings", UIAlertActionStyle.Default, (UIAlertAction obj) => { UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString)); })); settingsAlertController.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Destructive, (UIAlertAction obj) => { })); this.PresentViewController(settingsAlertController, true, null); }
public static void AuthorizeRestricedAPIAccess(WTAuthorizationRequestManager authorizationRequestManager, WTFeatures requiredFeatures, Action successHandler, Action <UIAlertController> errorHandler) { if (!authorizationRequestManager.RequestingRestrictedAppleiOSSDKAPIAuthorization) { NSOrderedSet <NSNumber> restrictedAppleiOSSDKAPIs = WTAuthorizationRequestManager .RestrictedAppleiOSSDKAPIAuthorizationsForRequiredFeatures(requiredFeatures); authorizationRequestManager.RequestRestrictedAppleiOSSDKAPIAuthorization(restrictedAppleiOSSDKAPIs, (bool success, NSError error) => { if (success) { successHandler(); } else { NSDictionary unauthorizedAPIInfo = (NSDictionary)error.UserInfo.ObjectForKey(WTAuthorizationRequestManager.WTUnauthorizedAppleiOSSDKAPIsKey); string detailedAuthorizationErrorLogMessage = "The following authorization states do not meet the requirements: "; string missingAuthorizations = "In order to use the Wikitude SDK, please grant access to the following:"; foreach (NSString unauthorizedAPIKey in unauthorizedAPIInfo.Keys) { int authorizationStatus = Int32.Parse(unauthorizedAPIInfo.ObjectForKey(unauthorizedAPIKey).ToString()); detailedAuthorizationErrorLogMessage += "\n" + unauthorizedAPIKey.ToString() + " = " + WTAuthorizationRequestManager.StringFromAuthorizationStatusForUnauthorizedAppleiOSSDKAPI(authorizationStatus, unauthorizedAPIKey); missingAuthorizations += "\n* " + WTAuthorizationRequestManager.HumanReadableDescriptionForUnauthorizedAppleiOSSDKAPI(unauthorizedAPIKey); } Console.WriteLine(detailedAuthorizationErrorLogMessage); UIAlertController settingsAlertController = UIAlertController.Create("Required API authorizations missing", missingAuthorizations, UIAlertControllerStyle.Alert); settingsAlertController.AddAction(UIAlertAction.Create("Open Settings", UIAlertActionStyle.Default, (UIAlertAction action) => { UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(UIApplication.OpenSettingsUrlString)); })); settingsAlertController.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Destructive, null)); errorHandler(settingsAlertController); } }); } }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); if (!authorizationRequestManager.RequestingRestrictedAppleiOSSDKAPIAuthorization) { NSOrderedSet <NSNumber> restrictedAppleiOSSKDAPIs = WTAuthorizationRequestManager.RestrictedAppleiOSSDKAPIAuthorizationsForRequiredFeatures(WTFeatures.WTFeature_ImageTracking); authorizationRequestManager.RequestRestrictedAppleiOSSDKAPIAuthorization(restrictedAppleiOSSKDAPIs, (bool success, NSError error) => { authorized = success; if (success) { StartAR(); } else { handleAuthorizationError(error); } }); } }