我正在使用依赖注入从我的PCL项目启动Wikitude。
我正在使用WikitudeSDKSample。我已将它集成并编译。 当我运行它时,它会显示一个空白页面,顶部是VC名称。它从不初始化相机或AR。没有错误。
这是我到目前为止所得到的:
[assembly: Xamarin.Forms.Dependency(typeof(AugmentedRealityImplementation))]
namespace UXDivers.Artina.Grial
{
public class AugmentedRealityImplementation : IAugmentedReality
{
public AugmentedRealityImplementation() { }
public void LaunchWikitude()
{
var storyboard = UIStoryboard.FromName("MainStoryboard_iPhone", null);
var controller = storyboard.InstantiateViewController("StoryBoardViewController");
var window = UIApplication.SharedApplication.KeyWindow;
window.RootViewController = controller;
window.MakeKeyAndVisible();
}
}
}
这是Wikitude View Controller Class
using System;
using CoreGraphics;
using Foundation;
using UIKit;
using CoreMedia;
using Wikitude.Architect;
namespace UXDivers.Artina.Grial
{
public partial class ExampleArchitectViewDelegate : WTArchitectViewDelegate
{
public override void InvokedURL(WTArchitectView architectView, NSUrl url)
{
Console.WriteLine ("architect view invoked url: " + url);
}
public override void DidFinishLoadNavigation(WTArchitectView architectView, WTNavigation navigation)
{
Console.WriteLine ("architect view loaded navigation: " + navigation.OriginalURL);
}
public override void DidFailToLoadNavigation(WTArchitectView architectView, WTNavigation navigation, NSError error)
{
Console.WriteLine("architect view failed to load navigation. " + error.LocalizedDescription);
}
}
public partial class WikitudeSDKExampleViewController : UIViewController
{
private WTArchitectView architectView;
private WTAuthorizationRequestManager authorizationRequestManager = new WTAuthorizationRequestManager ();
private ExampleArchitectViewDelegate architectViewDelegate = new ExampleArchitectViewDelegate ();
private WTNavigation loadingArchitectWorldNavigation = null;
private bool authorized = false;
public WikitudeSDKExampleViewController (IntPtr handle) : base (handle)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
#region View lifecycle
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
this.architectView = new Wikitude.Architect.WTArchitectView ();
this.architectView.Delegate = architectViewDelegate;
this.architectView.ShouldAuthorizeRestrictedAPIs = false;
this.View.AddSubview (this.architectView);
this.architectView.TranslatesAutoresizingMaskIntoConstraints = false;
NSDictionary views = new NSDictionary (new NSString ("architectView"), architectView);
this.View.AddConstraints (NSLayoutConstraint.FromVisualFormat("|[architectView]|", 0, null, views));
this.View.AddConstraints (NSLayoutConstraint.FromVisualFormat("V:|[architectView]|", 0, null, views));
architectView.SetLicenseKey ("qb0APVM+s+0ab+QN8CIGXAjxmetYYiCSQ6wK3mnWl31YV2BKuDT8EncCMuZcCev2rgnvaVzhU3hcfoXUv3rwCTZ7HEgNUD0Fp+qntzv7Usjf2fBuQz1HZ9IEhr7o9O5YbKdwsTdIf1wEywQKAGYmLgDwfoaaE8Bciyh7L1Xm1i1TYWx0ZWRfX4squ7p4M/QBfCETAiRlme5mizo+X1Z5K1y4xpS6JNRp+JE5aIbw4rcgF2Onp4wmQypiD9lXMpM7vv0sCDU3NGOorbw1ni/kahQpXWFxRpSnVRYu772ATIZ/JWMY7O60m0JWkA1YgSczMV4SioFGA1R2tReC1l9rQw+hN395FoV40zceQykZTlb/KPW3n3+3FlgfHXgq+A0KrCv+TfbZhAnQg6z39ED0unJXnCdIdjHve1WhUClaovbcqOGrdllxVgi/85V+RG9TerH/owLju07FS5QwPL+LuHkbQ0blPqoK7uvQv+cUSXc6Chxjn3Ht49TIiFt9ishzhxfuAvTsSg84kyO0Es+aQNwZV/anS6h1i7R9UDn8I2XXZKu5IHSGaEk7gQstVgyLdvMDOyHt4LJk/q28UCEXxIOYLTcewhQyevfgmeyV2a3VnXWEMpbIqGITf343UsxZq62WD4y/iTwbwAFTun9X058QqSS0Tn6TcXH5Ef4RmJo=");
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, (notification) => {
StartAR();
});
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillResignActiveNotification, (notification) => {
StopAR();
});
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
}
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);
}
});
}
}
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
}
public override void ViewDidDisappear (bool animated)
{
base.ViewDidDisappear (animated);
StopAR ();
}
#endregion
#region Rotation
public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, double duration)
{
base.WillRotate (toInterfaceOrientation, duration);
architectView.SetShouldRotateToInterfaceOrientation (true, toInterfaceOrientation);
}
public override bool ShouldAutorotate()
{
return true;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
{
return UIInterfaceOrientationMask.All;
}
#endregion
#region Segue
[Action("UnwindToMainViewController")]
public void UnwindToMainViewController()
{
}
#endregion
#region Private Methods
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);
}
private void StartAR()
{
if (authorized)
{
if (!architectView.IsRunning)
{
architectView.Start((startupConfiguration) =>
{
// use startupConfiguration.CaptureDevicePosition = AVFoundation.AVCaptureDevicePosition.Front; to start the Wikitude SDK with an active front cam
startupConfiguration.CaptureDevicePosition = AVFoundation.AVCaptureDevicePosition.Back;
startupConfiguration.CaptureDeviceResolution = WTCaptureDeviceResolution.WTCaptureDeviceResolution_AUTO;
startupConfiguration.TargetFrameRate = CMTime.PositiveInfinity; // resolves to WTMakeTargetFrameRateAuto();
}, (bool isRunning, NSError startupError) => {
if (isRunning)
{
if (null == loadingArchitectWorldNavigation)
{
var path = NSBundle.MainBundle.BundleUrl.AbsoluteString + "x_Demo_2_SolarSystem(Geo)/index.html";
loadingArchitectWorldNavigation = architectView.LoadArchitectWorldFromURL(NSUrl.FromString(path), Wikitude.Architect.WTFeatures.WTFeature_ImageTracking);
}
}
else
{
Console.WriteLine("Unable to start Wikitude SDK. Error (start ar): " + startupError.LocalizedDescription);
}
});
}
architectView.SetShouldRotateToInterfaceOrientation(true, UIApplication.SharedApplication.StatusBarOrientation);
}
}
private void StopAR()
{
if (architectView.IsRunning)
{
architectView.Stop();
}
}
#endregion
}
}
这是iphone故事板
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="15">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733.0"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="WikitudeSDKExampleViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="3"/>
<viewControllerLayoutGuide type="bottom" id="4"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="64" width="768" height="960"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem title="Wikitude SDK" id="585" key="navigationItem">
<barButtonItem key="rightBarButtonItem" title="Info" id="588">
<connections>
<segue id="780" destination="599" kind="modal" modalPresentationStyle="formSheet"/>
</connections>
<color key="tintColor" colorSpace="calibratedRGB" red="1" green="0.49803921568627452" blue="0" alpha="1"/>
</barButtonItem>
</navigationItem>
<extendedEdge key="edgesForExtendedLayout" bottom="YES"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-333" y="-299"/>
</scene>
<scene sceneID="14">
<objects>
<navigationController id="15" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="17">
<rect key="frame" x="0.0" y="20" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue id="586" destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="18" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1230" y="-294"/>
</scene>
<scene sceneID="589">
<objects>
<tableViewController id="590" sceneMemberID="viewController" customClass="WTSDKInformationViewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="592">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="590" id="593"/>
<outlet property="delegate" destination="590" id="594"/>
</connections>
<sections>
<tableViewSection headerTitle="SDK Information" id="605">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="606" rowHeight="44" style="IBUITableViewCellStyleValue1" textLabel="1061" detailTextLabel="1062">
<rect key="frame" x="0.0" y="55.5" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="606" id="607">
<rect key="frame" x="0.0" y="0.0" width="768" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Version Number:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1061">
<rect key="frame" x="48" y="12" width="128" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1062">
<rect key="frame" x="661" y="12" width="59" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Build Information" id="612">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="613" rowHeight="44" style="IBUITableViewCellStyleValue1" textLabel="1063" detailTextLabel="1064">
<rect key="frame" x="0.0" y="293" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="613" id="614">
<rect key="frame" x="0.0" y="0.0" width="768" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Build Date:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1063">
<rect key="frame" x="48" y="12" width="83.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1064">
<rect key="frame" x="661" y="12" width="59" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="615" rowHeight="44" style="IBUITableViewCellStyleValue1" textLabel="1065" detailTextLabel="1066">
<rect key="frame" x="0.0" y="337" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="615" id="616">
<rect key="frame" x="0.0" y="0.0" width="768" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Build Number:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1065">
<rect key="frame" x="48" y="12" width="109" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1066">
<rect key="frame" x="661" y="12" width="59" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="617" rowHeight="44" style="IBUITableViewCellStyleValue1" textLabel="1067" detailTextLabel="1068">
<rect key="frame" x="0.0" y="381" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="617" id="618">
<rect key="frame" x="0.0" y="0.0" width="768" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Build Configuration:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1067">
<rect key="frame" x="48" y="12" width="151" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1068">
<rect key="frame" x="661" y="12" width="59" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<color key="separatorColor" colorSpace="calibratedRGB" red="1" green="0.49803921568627452" blue="0" alpha="1"/>
</tableView>
<navigationItem key="navigationItem" title="Wikitude Xamarin Component" id="591">
<barButtonItem key="rightBarButtonItem" id="619" style="done" systemItem="done">
<color key="tintColor" colorSpace="calibratedRGB" red="1" green="0.49803921568627452" blue="0" alpha="1"/>
<connections>
<segue id="1059" destination="603" kind="unwind" unwindAction="UnwindToMainViewController"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="597" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="603" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="665" y="-1542"/>
</scene>
<scene sceneID="598">
<objects>
<navigationController id="599" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="601">
<rect key="frame" x="0.0" y="20" width="768" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="590" kind="relationship" relationship="rootViewController" id="600"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="602" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-317" y="-1541"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackOpaque"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
<resources>
<image name="Default-568h.png" width="320" height="568"/>
<image name="1_ImageRecognition_1_ImageOnTarget/assets/imageOne.png" width="446" height="1024"/>
<image name="1_ImageRecognition_1_ImageOnTarget/assets/surfer.png" width="38" height="50"/>
</resources>
</document>
答案 0 :(得分:0)
我删除了所有内容并重新创建了它,并使用了以下代码:
'public void LaunchWikitude()
{
var storyboard = UIStoryboard.FromName("MainStoryboard_iPhone", null);
var controller = storyboard.InstantiateViewController("StoryBoardViewController") as UIViewController;
var window = UIApplication.SharedApplication.KeyWindow;
window.RootViewController = controller;
window.MakeKeyAndVisible();
}'