Akhil Bhaskar

Akhil Bhaskar

  • NA
  • 81
  • 16.1k

Universal Windows Platform?

Sep 20 2017 2:04 AM
Hi everyone I am developing a universal windows platform game which is compiled from unity. In that game I want to show Microsoft ads(both banner and interstitial).
My problem is in the framework where I load the ads in the framework I don't know.
 
Can anyone give the solution for this problem?
 
I mentioned framework below,
 
Thanks in advance.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using Windows.ApplicationModel.Activation;  
  4. using Windows.Foundation;  
  5. using Windows.Storage;  
  6. using Windows.UI;  
  7. using Windows.UI.Core;  
  8. using Windows.UI.Xaml;  
  9. using Windows.UI.Xaml.Controls;  
  10. using Windows.UI.Xaml.Media;  
  11. using Windows.UI.Xaml.Navigation;  
  12. using System.Diagnostics;  
  13. using UnityPlayer;  
  14. using Windows.Networking.Connectivity;  
  15. using Windows.ApplicationModel.DataTransfer;  
  16. using Microsoft.Advertising.WinRT.UI;  
  17. using Windows.UI.Popups;  
  18. using com.vmax.windows.ads.wp10;  
  19. using com.vmax.windows.ads;  
  20. #if DEBUG  
  21. using store = Windows.ApplicationModel.Store.CurrentAppSimulator;  
  22. using Windows.ApplicationModel.Store;  
  23. using System.Net.NetworkInformation;  
  24. #else  
  25. using store = Windows.ApplicationModel.Store.CurrentApp;  
  26. using Windows.ApplicationModel.Store;  
  27. #endif  
  28. namespace HopTheBall  
  29. {  
  30. ///  
  31. /// An empty page that can be used on its own or navigated to within a Frame.  
  32. ///  
  33. public sealed partial class MainPage : Page  
  34. {  
  35. private WinRTBridge.WinRTBridge _bridge;  
  36. private SplashScreen splash;  
  37. private Rect splashImageRect;  
  38. private WindowSizeChangedEventHandler onResizeHandler;  
  39. //private TypedEventHandler onRotationChangedHandler;  
  40. private const string interstitialTestAdspotId = "8063";  
  41. public static string InApp_ConsumableId = "Beer100";  
  42. public static string InApp_NonConsumableId = "Pong100";  
  43. private string msRemoveAdsId = "adsRemoved";  
  44. private int msRemoveadsValue = 1;  
  45. //App Launch URL  
  46. private string appLaunchUrl = "http://www.windowsphone.com/s?appid=169381fb-0fcb-4f42-852d-a1d1ad49c777";  
  47. private int totalInapItems = 7;  
  48. private string[] ApreciationMessage;  
  49. private Random randomMessage;  
  50. private DataTransferManager dataTransferManager;  
  51. public string shareData;  
  52. public MainPage()  
  53. {  
  54. this.InitializeComponent();  
  55. NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;  
  56. AppCallbacks appCallbacks = AppCallbacks.Instance;  
  57. // Setup scripting bridge  
  58. _bridge = new WinRTBridge.WinRTBridge();  
  59. appCallbacks.SetBridge(_bridge);  
  60. appCallbacks.RenderingStarted += () => { RemoveSplashScreen(); };  
  61. CustomAdMediator.Visibility = Visibility.Collapsed;  
  62. #if !UNITY_WP_8_1  
  63. appCallbacks.SetKeyboardTriggerControl(this);  
  64. #endif  
  65. appCallbacks.SetSwapChainPanel(GetSwapChainPanel());  
  66. appCallbacks.SetCoreWindowEvents(Window.Current.CoreWindow);  
  67. appCallbacks.InitializeD3DXAML();  
  68. splash = ((App)App.Current).splashScreen;  
  69. GetSplashBackgroundColor();  
  70. OnResize();  
  71. onResizeHandler = new WindowSizeChangedEventHandler((o, e) => OnResize());  
  72. Window.Current.SizeChanged += onResizeHandler;  
  73. #if UNITY_WP_8_1  
  74. onRotationChangedHandler = new TypedEventHandler((di, o) => { OnRotate(di); });  
  75. ExtendedSplashImage.RenderTransformOrigin = new Point(0.5, 0.5);  
  76. var displayInfo = DisplayInformation.GetForCurrentView();  
  77. displayInfo.OrientationChanged += onRotationChangedHandler;  
  78. OnRotate(displayInfo);  
  79. SetupLocationService();  
  80. #endif  
  81. }  
  82. ///  
  83. /// Invoked when this page is about to be displayed in a Frame.  
  84. ///  
  85. /// Event data that describes how this page was reached. The Parameter  
  86. /// property is typically used to configure the page.  
  87. protected override void OnNavigatedTo(NavigationEventArgs e)  
  88. {  
  89. splash = (SplashScreen)e.Parameter;  
  90. OnResize();  
  91. }  
  92. private void OnResize()  
  93. {  
  94. if (splash != null)  
  95. {  
  96. splashImageRect = splash.ImageLocation;  
  97. PositionImage();  
  98. }  
  99. }  
  100. #if UNITY_WP_8_1  
  101. private void OnRotate(DisplayInformation di)  
  102. {  
  103. // system splash screen doesn't rotate, so keep extended one rotated in the same manner all the time  
  104. int angle = 0;  
  105. switch (di.CurrentOrientation)  
  106. {  
  107. case DisplayOrientations.Landscape:  
  108. angle = -90;  
  109. break;  
  110. case DisplayOrientations.LandscapeFlipped:  
  111. angle = 90;  
  112. break;  
  113. case DisplayOrientations.Portrait:  
  114. angle = 0;  
  115. break;  
  116. case DisplayOrientations.PortraitFlipped:  
  117. angle = 180;  
  118. break;  
  119. }  
  120. var rotate = new RotateTransform();  
  121. rotate.Angle = angle;  
  122. ExtendedSplashImage.RenderTransform = rotate;  
  123. }  
  124. #endif  
  125. private void PositionImage()  
  126. {  
  127. var inverseScaleX = 1.0f;  
  128. var inverseScaleY = 1.0f;  
  129. #if UNITY_WP_8_1  
  130. inverseScaleX = inverseScaleX / DXSwapChainPanel.CompositionScaleX;  
  131. inverseScaleY = inverseScaleY / DXSwapChainPanel.CompositionScaleY;  
  132. #endif  
  133. ExtendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X * inverseScaleX);  
  134. ExtendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y * inverseScaleY);  
  135. ExtendedSplashImage.Height = splashImageRect.Height * inverseScaleY;  
  136. ExtendedSplashImage.Width = splashImageRect.Width * inverseScaleX;  
  137. }  
  138. private async void GetSplashBackgroundColor()  
  139. {  
  140. try  
  141. {  
  142. StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AppxManifest.xml"));  
  143. string manifest = await FileIO.ReadTextAsync(file);  
  144. int idx = manifest.IndexOf("SplashScreen");  
  145. manifest = manifest.Substring(idx);  
  146. idx = manifest.IndexOf("BackgroundColor");  
  147. if (idx < 0) // background is optional  
  148. return;  
  149. manifest = manifest.Substring(idx);  
  150. idx = manifest.IndexOf("\"");  
  151. manifest = manifest.Substring(idx + 1);  
  152. idx = manifest.IndexOf("\"");  
  153. manifest = manifest.Substring(0, idx);  
  154. int value = 0;  
  155. bool transparent = false;  
  156. if (manifest.Equals("transparent"))  
  157. transparent = true;  
  158. else if (manifest[0] == '#'// color value starts with #  
  159. value = Convert.ToInt32(manifest, 16) & 0x00FFFFFF;  
  160. else  
  161. return// at this point the value is 'red', 'blue' or similar, Unity does not set such, so it's up to user to fix here as well  
  162. byte r = (byte)(value >> 16);  
  163. byte g = (byte)((value & 0x0000FF00) >> 8);  
  164. byte b = (byte)(value & 0x000000FF);  
  165. await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.High, delegate ()  
  166. {  
  167. byte a = (byte)(transparent ? 0x00 : 0xFF);  
  168. ExtendedSplashGrid.Background = new SolidColorBrush(Color.FromArgb(a, r, g, b));  
  169. });  
  170. }  
  171. catch (Exception)  
  172. { }  
  173. }  
  174. public SwapChainPanel GetSwapChainPanel()  
  175. {  
  176. return DXSwapChainPanel;  
  177. }  
  178. public void RemoveSplashScreen()  
  179. {  
  180. try  
  181. {  
  182. AppCallbacks.Instance.InvokeOnAppThread(new AppCallbackItem(() =>  
  183. {  
  184. //Communication Handler  
  185. if (UnityEngine.GameObject.Find("ExternalInterfaceHandler") != null)  
  186. {  
  187. var mvGo = UnityEngine.GameObject.Find("ExternalInterfaceHandler");  
  188. if (mvGo != null)  
  189. {  
  190. var InterfaceHandler = mvGo.GetComponent();  
  191. InterfaceHandler.OnSendRequestEvent += OnRequestFromGame;  
  192. }  
  193. }  
  194. randomMessage = new Random();  
  195. ApreciationMessage = new String[]  
  196. {  
  197. "Fantastic""Superb""Awesome""Great""Amazing""Excellent""magnificent""Impressive"  
  198. };  
  199. }), false);  
  200. }  
  201. catch (Exception me)  
  202. {  
  203. //System.Diagnostics.Debug.WriteLine("" + me.Message);  
  204. }  
  205. DXSwapChainPanel.Children.Remove(ExtendedSplashGrid);  
  206. if (onResizeHandler != null)  
  207. {  
  208. Window.Current.SizeChanged -= onResizeHandler;  
  209. onResizeHandler = null;  
  210. #if UNITY_WP_8_1  
  211. DisplayInformation.GetForCurrentView().OrientationChanged -= onRotationChangedHandler;  
  212. onRotationChangedHandler = null;  
  213. #endif  
  214. }  
  215. }  
  216. //Application Quit  
  217. private async void ApplicationQuit()  
  218. {  
  219. var dlg = new ContentDialog()  
  220. {  
  221. Title = "Exit",  
  222. Content = "Are You Sure?",  
  223. PrimaryButtonText = "Yes",  
  224. SecondaryButtonText = "No"  
  225. };  
  226. var result = await dlg.ShowAsync();  
  227. if (result == ContentDialogResult.Primary)  
  228. {  
  229. Application.Current.Exit();  
  230. }  
  231. else  
  232. {  
  233. Debug.WriteLine("No");  
  234. }  
  235. }  
  236. public void OnRequestFromGame(eEXTERNAL_REQ_TYPE ReqType, string strData)  
  237. {  
  238. System.Diagnostics.Debug.WriteLine("Request Type---------" + ReqType + " StrData---------" + strData);  
  239. AppCallbacks.Instance.InvokeOnUIThread(new AppCallbackItem(() =>  
  240. {  
  241. switch (ReqType)  
  242. {  
  243. case eEXTERNAL_REQ_TYPE.ApplicationQuit:  
  244. {  
  245. ApplicationQuit();  
  246. }  
  247. break;  
  248. case eEXTERNAL_REQ_TYPE.InAppConsumable:  
  249. {  
  250. ExternalInterfaceHandler.Instance.Receiver("true");  
  251. try  
  252. {  
  253. var mvProductId = InApp_ConsumableId + strData;  
  254. var licence = store.LicenseInformation.ProductLicenses[mvProductId];  
  255. if (licence.IsActive)  
  256. {  
  257. ExternalInterfaceHandler.Instance.Receiver("true");  
  258. mDoPurchaseOrFullfillItem(mvProductId, truetrue);  
  259. }  
  260. else  
  261. {  
  262. mDoPurchaseOrFullfillItem(mvProductId, falsetrue);  
  263. }  
  264. }  
  265. catch (Exception ex)  
  266. {  
  267. ExternalInterfaceHandler.Instance.Receiver("false");  
  268. }  
  269. }  
  270. break;  
  271. case eEXTERNAL_REQ_TYPE.InAppNonConsumable:  
  272. {  
  273. ExternalInterfaceHandler.Instance.Receiver("true");  
  274. try  
  275. {  
  276. var mvProductId = InApp_NonConsumableId + strData;  
  277. var licence = store.LicenseInformation.ProductLicenses[mvProductId];  
  278. if (licence.IsActive)  
  279. {  
  280. ExternalInterfaceHandler.Instance.Receiver("true");  
  281. }  
  282. else  
  283. {  
  284. mDoPurchaseOrFullfillItem(mvProductId, falsefalse);  
  285. }  
  286. }  
  287. catch (Exception ex)  
  288. {  
  289. ExternalInterfaceHandler.Instance.Receiver("false");  
  290. }  
  291. }  
  292. break;  
  293. case eEXTERNAL_REQ_TYPE.Show_Banner_Top_Ads:  
  294. {  
  295. // Debug.WriteLine("Show_Banner_Top_Ads_Called");  
  296. try  
  297. {  
  298. ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();  
  299. //check if net is available or not  
  300. if (InternetConnectionProfile != null)  
  301. {  
  302. if (CustomAdMediator != null)  
  303. {  
  304. CustomAdMediator.VerticalAlignment = VerticalAlignment.Top;  
  305. CustomAdMediator.Visibility = Visibility.Visible;  
  306. }  
  307. else  
  308. {  
  309. CustomAdMediator.VerticalAlignment = VerticalAlignment.Top;  
  310. CustomAdMediator.Visibility = Visibility.Visible;  
  311. }  
  312. }  
  313. }  
  314. catch  
  315. {  
  316. }  
  317. }  
  318. break;  
  319. case eEXTERNAL_REQ_TYPE.Show_Banner_Bottom_Ads:  
  320. {  
  321. // Debug.WriteLine("Show_Banner_Bottom_Ads_Called");  
  322. try  
  323. {  
  324. ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();  
  325. //check if net is available or not  
  326. if (InternetConnectionProfile != null)  
  327. {  
  328. if (CustomAdMediator != null)  
  329. {  
  330. CustomAdMediator.VerticalAlignment = VerticalAlignment.Bottom;  
  331. CustomAdMediator.Visibility = Visibility.Visible;  
  332. }  
  333. else  
  334. {  
  335. CustomAdMediator.VerticalAlignment = VerticalAlignment.Bottom;  
  336. CustomAdMediator.Visibility = Visibility.Visible;  
  337. }  
  338. }  
  339. }  
  340. catch  
  341. {  
  342. }  
  343. }  
  344. break;  
  345. case eEXTERNAL_REQ_TYPE.Show_FullScreen_Ads:  
  346. {  
  347. // Debug.WriteLine("Show_FullScreen_Ads_Called");  
  348. try  
  349. {  
  350. ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();  
  351. //check if net is available or not  
  352. if (InternetConnectionProfile != null)  
  353. {  
  354. VMAXAdView adView = new VMAXAdView();  
  355. adView.AdspotId = interstitialTestAdspotId;  
  356. adView.UX = AdUX.Interstitial; // To specify banner ads.  
  357. adView.LoadAd();  
  358. adView.ShowAd();  
  359. }  
  360. }  
  361. catch  
  362. {  
  363. }  
  364. }  
  365. break;  
  366. case eEXTERNAL_REQ_TYPE.Hide_Banner_Ads:  
  367. {  
  368. // Debug.WriteLine("Hide_Banner_Ads_Called");  
  369. if (CustomAdMediator != null)  
  370. {  
  371. CustomAdMediator.Visibility = Visibility.Collapsed;  
  372. }  
  373. }  
  374. break;  
  375. //Google Universal Analytics  
  376. case eEXTERNAL_REQ_TYPE.GoogleAnalyticsScreen:  
  377. {  
  378. GoogleAnalytics.EasyTracker.GetTracker().SetStartSession(true);  
  379. GoogleAnalytics.EasyTracker.GetTracker().SendView(strData);  
  380. }  
  381. break;  
  382. case eEXTERNAL_REQ_TYPE.GoogleAnalyticsEvent:  
  383. {  
  384. GoogleAnalytics.EasyTracker.GetTracker().SendEvent(strData, nullnull, 0);  
  385. }  
  386. break;  
  387. case eEXTERNAL_REQ_TYPE.sendLiveTileNotify:  
  388. {  
  389. AppCallbacks.Instance.InvokeOnUIThread(new AppCallbackItem(() =>  
  390. {  
  391. UpdateTile(strData);  
  392. }), false);  
  393. }  
  394. break;  
  395. case eEXTERNAL_REQ_TYPE.ShareScore:  
  396. {  
  397. try  
  398. {  
  399. shareData = strData;  
  400. dataTransferManager = DataTransferManager.GetForCurrentView();  
  401. dataTransferManager.DataRequested += new TypedEventHandler(this.OnDataRequested);  
  402. DataTransferManager.ShowShareUI();  
  403. }  
  404. catch  
  405. {  
  406. }  
  407. }  
  408. break;  
  409. case eEXTERNAL_REQ_TYPE.RateApplication:  
  410. {  
  411. try  
  412. {  
  413. ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();  
  414. if (InternetConnectionProfile != null//check if net is available or not  
  415. {  
  416. RateApp();  
  417. }  
  418. }  
  419. catch  
  420. {  
  421. ExternalInterfaceHandler.Instance.Receiver("false");  
  422. }  
  423. }  
  424. break;  
  425. case eEXTERNAL_REQ_TYPE.MoreGames:  
  426. {  
  427. string uriToLaunch = "http://www.windowsphone.com/en-us/store/search?q=dumadu+games+pvt+ltd";  
  428. Uri Url;  
  429. Url = new Uri(uriToLaunch);  
  430. }  
  431. break;  
  432. default:  
  433. break;  
  434. }  
  435. }), false);  
  436. }  
  437. private void SocialMediaShare()  
  438. {  
  439. }  
  440. private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)  
  441. {  
  442. Uri appLaunchURI = ValidateAndGetUri(appLaunchUrl);  
  443. string dataPackageText = "Wow! It's " + ApreciationMessage[randomMessage.Next(0, ApreciationMessage.Length)] + " beat my Levels if you can! : " + shareData;  
  444. if (!String.IsNullOrEmpty(dataPackageText))  
  445. {  
  446. DataPackage requestData = e.Request.Data;  
  447. requestData.Properties.Title = "BeerPong TrickShot";  
  448. requestData.SetText(dataPackageText + " Have you tried it ? Go for the link." + appLaunchURI);  
  449. }  
  450. else  
  451. {  
  452. //request.FailWithDisplayText("Enter the text you would like to share and try again.");  
  453. }  
  454. }  
  455. private Uri ValidateAndGetUri(string uriString)  
  456. {  
  457. Uri uri = null;  
  458. try  
  459. {  
  460. uri = new Uri(uriString);  
  461. }  
  462. catch (FormatException)  
  463. {  
  464. }  
  465. return uri;  
  466. }  
  467. private async void RateApp()  
  468. {  
  469. //await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid="+CurrentApp.AppId));  
  470. await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp"));  
  471. }  
  472. private void UpdateTile(string tileData)  
  473. {  
  474. UnityEngine.WSA.Tile liveTile = UnityEngine.WSA.Tile.main;  
  475. liveTile.Update("ms-appx:///Assets/SquareTile.png""ms-appx:///Assets/Wide310x150Logo.scale-100.png""ms-appx:///Assets/Square310x310Logo.scale-100.png", tileData); //mwl  
  476. }  
  477. private async void mDoPurchaseOrFullfillItem(string msProductId, bool isRestore, bool itemIsConsumable)  
  478. {  
  479. if (isRestore && itemIsConsumable)  
  480. {  
  481. IReadOnlyList LstProcts = await store.GetUnfulfilledConsumablesAsync();  
  482. for (int i = 0; i <= LstProcts.Count; i++)  
  483. {  
  484. FulfillmentResult result = await store.ReportConsumableFulfillmentAsync(LstProcts[i].ProductId, LstProcts[i].TransactionId);//TransactionId);  
  485. switch (result)  
  486. {  
  487. case FulfillmentResult.Succeeded:  
  488. break;  
  489. case FulfillmentResult.NothingToFulfill:  
  490. case FulfillmentResult.PurchasePending:  
  491. case FulfillmentResult.PurchaseReverted:  
  492. case FulfillmentResult.ServerError:  
  493. // Win8StoreInterfaceHandler._temTextToDisplayInAppRes = "server Error";  
  494. break;  
  495. default:  
  496. break;  
  497. }  
  498. }  
  499. }  
  500. else  
  501. {  
  502. try  
  503. {  
  504. PurchaseResults purchaseResults = await store.RequestProductPurchaseAsync(msProductId);  
  505. switch (purchaseResults.Status)  
  506. {  
  507. case ProductPurchaseStatus.Succeeded:  
  508. {  
  509. if (itemIsConsumable)  
  510. {  
  511. FulfillmentResult result = await store.ReportConsumableFulfillmentAsync(msProductId, purchaseResults.TransactionId);  
  512. switch (result)  
  513. {  
  514. case FulfillmentResult.Succeeded:  
  515. ExternalInterfaceHandler.Instance.Receiver("true");  
  516. break;  
  517. case FulfillmentResult.NothingToFulfill:  
  518. case FulfillmentResult.PurchasePending:  
  519. case FulfillmentResult.PurchaseReverted:  
  520. case FulfillmentResult.ServerError:  
  521. // Win8StoreInterfaceHandler._temTextToDisplayInAppRes = "server Error";  
  522. break;  
  523. default:  
  524. break;  
  525. }  
  526. }  
  527. else  
  528. {  
  529. ExternalInterfaceHandler.Instance.Receiver("true");  
  530. }  
  531. //success  
  532. break;  
  533. case ProductPurchaseStatus.NotFulfilled:  
  534. {  
  535. FulfillmentResult result = await store.ReportConsumableFulfillmentAsync(msProductId, purchaseResults.TransactionId);  
  536. switch (result)  
  537. {  
  538. case FulfillmentResult.Succeeded:  
  539. ExternalInterfaceHandler.Instance.Receiver("true");  
  540. break;  
  541. case FulfillmentResult.NothingToFulfill:  
  542. case FulfillmentResult.PurchasePending:  
  543. case FulfillmentResult.PurchaseReverted:  
  544. case FulfillmentResult.ServerError:  
  545. // Win8StoreInterfaceHandler._temTextToDisplayInAppRes = "server Error";  
  546. break;  
  547. default:  
  548. break;  
  549. }  
  550. //success but not full filled  
  551. break;  
  552. case ProductPurchaseStatus.NotPurchased:  
  553. ExternalInterfaceHandler.Instance.Receiver("false");  
  554. break;  
  555. }  
  556. }  
  557. catch (Exception)  
  558. {  
  559. //Win8StoreInterfaceHandler._temTextToDisplayInAppRes = "In not Working";  
  560. }  
  561. }  
  562. }  
  563. #if !UNITY_WP_8_1  
  564. protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()  
  565. {  
  566. return new UnityPlayer.XamlPageAutomationPeer(this);  
  567. }  
  568. //Interstitial adds setup  
  569. //void MyInterstitialAd_AdReady(object sender, object e)  
  570. //{  
  571. // AdIsReady = true;  
  572. // AdReady();  
  573. //}  
  574. //public static async void AdReady()  
  575. //{  
  576. // var dialog = new MessageDialog("Ad Is Ready To Load");  
  577. // dialog.Commands.Add(new UICommand("ok"));  
  578. // await dialog.ShowAsync();  
  579. //}  
  580. //private void Button_Click(object sender, RoutedEventArgs e)  
  581. //{  
  582. // NewMethod();  
  583. //}  
  584. //private void NewMethod()  
  585. //{  
  586. // myInterstitialAd.RequestAd(AdType.Video, myAppId, myAdUnitId);  
  587. //}  
  588. //private void Button_Click_1(object sender, RoutedEventArgs e)  
  589. //{  
  590. // if (InterstitialAdState.Ready == myInterstitialAd.State)  
  591. // {  
  592. // myInterstitialAd.Show();  
  593. // }  
  594. //}  
  595. #else  
  596. // This is the default setup to show location consent message box to the user  
  597. // You can customize it to your needs, but do not remove it completely if your application  
  598. // uses location services, as it is a requirement in Windows Store certification process  
  599. private async void SetupLocationService()  
  600. {  
  601. AppCallbacks appCallbacks = AppCallbacks.Instance;  
  602. if (!appCallbacks.IsLocationCapabilitySet())  
  603. {  
  604. return;  
  605. }  
  606. const string settingName = "LocationContent";  
  607. bool userGaveConsent = false;  
  608. object consent;  
  609. var settings = Windows.Storage.ApplicationData.Current.LocalSettings;  
  610. var userWasAskedBefore = settings.Values.TryGetValue(settingName, out consent);  
  611. if (!userWasAskedBefore)  
  612. {  
  613. var messageDialog = new Windows.UI.Popups.MessageDialog("Can this application use your location?""Location services");  
  614. var acceptCommand = new Windows.UI.Popups.UICommand("Yes");  
  615. var declineCommand = new Windows.UI.Popups.UICommand("No");  
  616. messageDialog.Commands.Add(acceptCommand);  
  617. messageDialog.Commands.Add(declineCommand);  
  618. userGaveConsent = (await messageDialog.ShowAsync()) == acceptCommand;  
  619. settings.Values.Add(settingName, userGaveConsent);  
  620. }  
  621. else  
  622. {  
  623. userGaveConsent = (bool)consent;  
  624. }  
  625. if (userGaveConsent)  
  626. {   // Must be called from UI thread  
  627. appCallbacks.SetupGeolocator();  
  628. }  
  629. }  
  630. #endif  
  631. }  
  632. }  

Answers (1)