I'm trying to integrate Game Center into my iOS app. However, the achievement completion banner doesn't appear even if I set the ShowsCompletionBanner flag to true. I've been testing my app through iOS Simulator with iOS 14.
I'm using the following code (Xamarin.iOS):
var achievement = new GKAchievement("sample.achievement")
{
PercentComplete = 100,
ShowsCompletionBanner = true
};
achievement.ReportAchievement(null);
I can confirm that the ReportAchievement has succeeded since the achievement has been unlocked in the achievements view (GKGameCenterViewControllerState.achievements)
Added info: The completion banner appears when I put a breakpoint at the achievement.ReportAchievement(null) line. Also tried using achievement.ReportAchievementAsync() but I'm still encountering the same behavior.
Thanks in advance!
Try using static ReportAchievements instead of instance method being used.
You can see that in the Apple developer document https://developer.apple.com/documentation/gamekit/gkachievement?language=objc
But we also want info in where the API is being called from as there still may be an issue with async and timing.
Might be worth using a completion handler with the synchronous method which may reveal an error.
Related
Some of the iOS users of my app (one with an iPhone 6 with iOS 9.3.2) report that upon Force Quitting the app, they will see a black screen with only the Apple logo and a restart bar, and their device will restart. My own devices do not reproduce this and I do not receive any crash reports, so I've been unable to track this issue down. The users are under the impression that their phone or the app has crashed.
STEPS TO REPRODUCE
Open the app
Press the home button on the iPhone and then let the app go into the background for about 20 minutes.
Reopen the app
Double-tap the home button and swipe to Force Quit the app
Some users are reporting seeing a black screen with just the Apple logo and a restart bar at this point.
I do have background location updates running on the app, as well as a background process. I have tried ending this background task when the app re-enters the foreground, but that does not prevent the "apple logo" screen appearing for the users who are already seeing this effect.
Though there was no stacktrace so it was difficult to identify, the below ended up being my problem. I'm documenting it in case someone else runs into something similar.
As mentioned originally, I am creating background processes. This is how I was using them:
Old way:
I declared this at the top of my location manager:
private var bgId: UIBackgroundTaskIdentifier!
then, inside locationManager(_:didUpdateLocations:), I included these lines:
self.bgId = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler { _ in
UIApplication.sharedApplication().endBackgroundTask(self.bgId)
}
This was to keep the app alive in the background as long as possible as location readings came in. I thought that since I was using a single reference for bgId, the background tasks would be overwritten and only one would exist, no matter how often location updates came in.
New way:
First, I made bgId optional:
private var bgId: UIBackgroundTaskIdentifier?
Then, I replaced the earlier code snippet in locationManager(_:didUpdateLocations:) with this:
if self.bgId == nil {
self.bgId = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler { _ in
if let bgId = self.bgId {
UIApplication.sharedApplication().endBackgroundTask(bgId)
self.bgId = nil
}
}
}
It's possible that iOS was actually creating a ton of background processes and not overwriting them as I had thought. If true, this approach creates far fewer processes.
After making this change, I no longer see the "respring" effect of the apple logo and restart bar when going through the procedure in my question.
I have started playing with 3D touch quick actions for my app for iPhone 6S using code from apples developer site
This worked fine, but now i am unable to remove these quick actions.I only made changes to AppDelegate and I have removed this sample code from AppDelegate but quick actions still remain. Info.plist does not have any quick actions. Any ideas?
If you removed the code, than just delete app from your phone and rerun it.
If you need to do it programmatically for any reason, just call this function
func removeAllDynamicQuickActions() {
UIApplication.shared.shortcutItems?.removeAll()
}
I am currently testing my Game Center Aware App using the Game Center Sandbox, with one instance running on the iOS simulator and the other on an Retina iPad Mini. I have a view controller which needs to receive turn events, so I implement the method
player:receivedTurnEventForMatch:didBecomeActive:
in the GKLocalPlayerListener protocol, which my UIViewController subclass adopts, and then register for events with this line
[[GKLocalPlayer localPlayer] registerListener: self];
in the init method of the view controller. However, despite the Game Center App saying that the two instances of the game have connected, this method is rarely called on the iPad, and I dont't think I've ever seen the simulator instance calling it. However, going to the Game Center App shows that both instances are updated, showing that both instances are capable of receiving the event. What could be causing this?
I had the same problem on iOS 7/Xcode 5/iPhone 5.
To fix that issue you need just add "Game Center" entitlement to your App ID. You can do that by navigating to project's "Capabilities" tab in Xcode.
Please note that player:receivedTurnEventForMatch:didBecomeActive: will be fired on devices only.
The workaround I found for this issue on the simulator is to call the
loadMatchDataWithCompletionHandler:
method when a refresh button is pushed in the UI, which causes match data to be loaded in the simulator.
I have an iPad application where I have integrated the AdInsterstitialAd but it looks like the delegate method:
-(void)interstitialAdDidUnload
is no longer called when closing the ad in iOS 7. I wanted to know if anyone else has experienced this issue or has found away around this? The unload method is important for me because that is when I want to resume my app's timers (the app pauses itself while the ad is displayed).
I have looked on Apple's website and haven't found anything useful and their current InterstitialAd sample has the same issue.
I have nearly completed my first app. In testing on the device, I am getting a crash when I press the home button, with the error message
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
Based on these posts:
https://stackoverflow.com/search?q=how+to+shut+down+OpenGL
OpenGL ES crash on move background, iOS 5.1
I am pretty sure the problem is that my app is an extension of software that uses some sample code involving OpenGL (about which I have very little understanding) and that the OpenGL tasks are not shutting down properly on resignActive.
I tried the following in my AppDelegate with no luck:
- (void)applicationWillResignActive:(UIApplication *)application {
glFinish();
}
My app does not need to save any settings upon exit... it just needs to end.
Can anyone suggest a solution?
I am now working on a Sprite Kit game and I had a similar problem.
Check if you have on the screen the node that tells the FPS, because that might be rendering and causing the crash.. It did for me.
In applicationWillResignActive method I call my pause method as all of you.
*edit - and check for audio playing
To finish program at user push home button ?
on Xcode, choice Target and select Info tab.
Custom iOS Target Properties, add a Key named
Application does not run in background
and set Value
YES
Try it!
p.s. Not necessary write glFinish().