I implemented Game Center into an iOS app.
When the game center leader board view is opened from within the app and I press the 'Done' button, the view doesn't disappear.
Below the code to open the Game Center view:
GKGameCenterViewController gameCenter = new GKGameCenterViewController ();
gameCenter.ViewState = GKGameCenterViewControllerState.Leaderboards;
gameCenter.LeaderboardCategory = "myleaderboardddd";
gameCenter.LeaderboardTimeScope = GKLeaderboardTimeScope.AllTime;
gameCenter.Finished += delegate(object sender, EventArgs e) {
Console.WriteLine ("CLOSE THIS VIEW!"); // <-- THIS IS NEVER REACHED
this.DismissViewController(true, null);
};
this.PresentViewController (gameCenter, true, null);
Note that the Console.WriteLine is never reached when pressing the done button.
What do I do wrong?
I'm fairly sure this is identical to a bug report we had recently. This was fixed but it might not be released yet (in stable 6.2.x releases).
You might want to try the latest beta (6.3.x) version. It will have the fix (if only to confirm that the fix is coming and that this is not a different issue).
Related
I have Xamarin Native (iOS/Droid) app. In older iOS versions, navigating back to previous viewControllers can be done by swiping right with one animation that drags the current view for the screen. When updating to the newest iOS 13, this animation doesn't appear anymore. The ViewWillDissapper doesn't get called either.
What am i missing?
I already tried this changes:
this.ModalInPresentation = true;
this.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
NavigationController.InteractivePopGestureRecognizer.Enabled = true;
NavigationController.InteractivePopGestureRecognizer.Delegate = new MyGestureDelegate();
In iOS 13 , you can set that in the previous ViewController as follow :
UIViewControllerSecond viewControllerSecond = new UIViewControllerSecond();
viewControllerSecond.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
viewControllerSecond.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
PresentViewController(viewControllerSecond, true, null);
Then in second ViewController just DismissModalViewController(true); when back .
UISwipeGestureRecognizer swipeGesture = new UISwipeGestureRecognizer();
swipeGesture.Direction = UISwipeGestureRecognizerDirection.Right;
swipeGesture.AddTarget(() => { Console.WriteLine("-swipe-to-right-"); DismissViewController(true, null); });
View.AddGestureRecognizer(swipeGesture);
Have a look at this effect , whether it is needs .
The app is using Xamarin Native with Mvvm Cross. Turns out that the mvvm cross package in version 4.4 don't support iOS 13, and updating it to 5.7 solved my problem
We have an image with a gesture recognizer, which calls the CrossShare.Current.Share method. On Android this works fine but on iOS it does not. No error is thrown and there doesn't seem to be any issues, but the share sheet does not appear and from the user's point of view nothing happens when you click the button.
Have I missed some permissions or something somewhere?
This is my method;
async void On_Share(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
var message = "Check out this";
var title = "Share this";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title}, new ShareOptions { ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } });
}
else
{
NoInternetLabel.IsVisible = true;
}
}
It doesn't throw any errors and I can step through the method fine - it definitely hits the Share line. This problem is only showing on iOS, Android has no issues.
EDIT: Seems to be working fine (we've tried doing it natively as well - without plugin) but now I'm getting Warning: Attempt to present on whose view is not in the window hierarchy!
I am adding a "Today" extension widget to my iOS app that I made with Xamarin. I am following this walkthrough:
https://developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/
The widget appears in my Notification section in the simulator, but I can't get any contents to appear in it. It won't even create the UIViewController class that I made and set as the initial controller to start with (I know because it never hits my breakpoint in the constructor). I set it as the principal class with this key as explained in the walkthrough:
Any idea why? I also get this message when I first launch the app after adding the extension:
appname may slow down your phone the developer of this app needs to update it to improve its compatibility
I made a sample project, with Xamarin, and the widget does appear in this project when deployed on the simulator, just not with the contents that I'm trying to add in the CodeViewController class:
https://drive.google.com/file/d/0B8xKHTqtwfKtY0xZN0xaejhlZmM/view?usp=sharing
To save you 2 days I spent on it here is the solution.
Don't run it on simulator. It doesn't work (at least on mine).
Don't try to hit breakpoint in VS. When you testing your extension your app is in background mode. VS will not give you to stop in debugger. To prove run any of your apps, press home and try to set breakpoint in VS. VS will hang till you bring your app to foreground.
Do not use View.Frame in DidLoad. The size of the frame there is the whole screen size, so when you put your label to center you will not see it. Use WillAppear like this
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TodayMessage == null)
{
// Add label to view
TodayMessage = new UILabel(new CGRect(0, 0, View.Frame.Width, View.Frame.Height))
{
TextAlignment = UITextAlignment.Center,
BackgroundColor = UIColor.LightGray,
TextColor = UIColor.Black
};
// Calculate the values
var dayOfYear = DateTime.Now.DayOfYear;
var leapYearExtra = DateTime.IsLeapYear(DateTime.Now.Year) ? 1 : 0;
var daysRemaining = 365 + leapYearExtra - dayOfYear;
// Display the message
if (daysRemaining == 1)
{
TodayMessage.Text = String.Format("Today is day {0}. There is one day remaining in the year.", dayOfYear);
}
else
{
TodayMessage.Text = String.Format("Today is day {0}. There are {1} days remaining in the year.", dayOfYear, daysRemaining);
}
View.AddSubview(TodayMessage);
}
}
So I integrated amazon mobile ads into my unity/ios project. I have it all working to where I hide the ads every time a scene changes. Every time I open a scene, the ad shows. So it's all working fine except when you change scenes really quickly. I don't want ads in the main game as it obstructs the view of the users. Every time you get to the retry scene, if you quickly switch from that scene right before an ad loads, that ad will get stuck on the next scene which makes another ad show on top of it. Every time a scene changes it should be hiding the ad not matter how fast you change scenes. Is there any way to make sure it hides the ad if an ad is shown? I'm using the code below:
void Start() {
mobileAds = AmazonMobileAdsImpl.Instance;
ApplicationKey key = new ApplicationKey();
key.StringValue = iosKey;
mobileAds.SetApplicationKey(key);
ShouldEnable enable = new ShouldEnable();
enable.BooleanValue = true;
mobileAds.EnableTesting(enable);
mobileAds.EnableLogging(enable);
Placement placement = new Placement();
placement.Dock = Dock.BOTTOM;
placement.HorizontalAlign = HorizontalAlign.CENTER;
placement.AdFit = AdFit.FIT_AD_SIZE;
response = mobileAds.CreateFloatingBannerAd(placement);
string adType = response.AdType.ToString();
long identifer = response.Identifier;
newResponse = mobileAds.LoadAndShowFloatingBannerAd(response);
bool loadingStarted = newResponse.BooleanValue;
}
void OnDestroy() {
mobileAds.CloseFloatingBannerAd(response);
response = null;
mobileAds = null;
newResponse = null;
}
When did you download the Unity Plugin? There were some issues in an early version of the plugin that this sounds like (the whole, one ad loading over top of another thing). If you have not updated it recently, try downloading the latest version from Amazon and see if the issue still occurs.
The close ad API
mobileAds.CloseFloatingBannerAd(response);
will only work if the ad is already loaded. You need to register for the ad loaded event. If the scene is destroyed, then you would close the ad when the ad loaded event tiggers.
You can register for AdLoaded event as follows, Documentation
using com.amazon.mas.cpt.ads;
bool sceneDestroyed = false; //tracks if scene is destroyed
//Obtain object used to interact with the plugin
IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
// Define event handler
private void EventHandler(Ad args)
{
if (sceneDestroyed)
{
mobileAds.CloseFloatingBannerAd(response);
}
else
{
//Do some other job
}
}
//Register for an event
mobileAds.AddAdLoadedListener(EventHandler);
void OnDestroy()
{
sceneDestroyed = true;
}
I'm writing Windows Phone 8 app that needs to get location of device (do not track changes, just get location). I added next code to the method OnNavigatedTo() of my start page but after launching app, the progress indicator does not hide even after 10 seconds timeout. But if I navigate to another page and then go back, everything works fine. This happens on the emulator, I don't have a real device. What am I doing wrong?
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if(_geoPosition == null)
{
try
{
var geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
_progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
Text = "Getting current location, please wait...",
IsVisible = true
};
SystemTray.SetIsVisible(this, true);
SystemTray.SetProgressIndicator(this, _progressIndicator);
_geoPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
_progressIndicator.IsVisible = false;
SystemTray.SetIsVisible(this, false);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings");
}
}
}
Thanks!
UPD: just tried to add this code to empty project and it works fine. Tried to comment out some parts of OnNavigatedTo that I did not include to the snippet and found out that the reason somewhere in initialization of data source for this page. I'm sorry for false alarm.
Your code works fine for me, try the classic restart VS and the projecy!
The code should work, tested it with an emulator and a device (nokia 820).
Best of luck