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.
Related
Should my app be updated to Scene Delegate from App Delegate. My app supports ios 13.0 and up
first you have to understand what is difference
You could think of them as the global and private versions. One is shared and the other is limited to the individual owner. In a way, they are exactly what you would expect by the names.
Multi-window support is happening
Next time you create a new Xcode project you’ll see your AppDelegate has split in two: AppDelegate.swift and SceneDelegate.swift. This is a result of the new multi-window support that landed with iPadOS, and effectively splits the work of the app delegate in two.
From iOS 13 onwards, your app delegate should:
Set up any data that you need for the duration of the app.
Respond to any events that focus on the app, such as a file being shared with you.
Register for external services, such as push notifications.
Configure your initial scenes.
In contrast, scene delegates are there to handle one instance of your app’s user interface. So, if the user has created two windows showing your app, you have two scenes, both backed by the same app delegate.
Keep in mind that these scenes are designed to work independently from each other. So, your application no longer moves to the background, but instead individual scenes do – the user might move one to the background while keeping another open.
at last I will say that you can go with Scene Delegate
Courtesy of https://www.hackingwithswift.com/articles/193/whats-new-in-ios-13
I'm finding it extraordinarily difficult to categorize and account for what events I get (or don't get) when the user swipes my app up in the app switcher on iOS 13. This seems to be because of changes caused by the multiple scene support. What are the events that I get in that situation?
Let's assume that your app supports window scenes. So what the user is swiping up in the app switcher is really a scene, not your app as a whole. Then the possibilities appear to be as follows.
On an iPhone
If the scene was frontmost:
sceneDidEnterBackground
applicationWillTerminate(_:)
But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because the app isn't running.
On an iPad, if the app does not support multiple windows
If the scene was frontmost:
sceneDidDisconnect(_:)
application(_:didDiscardSceneSessions:)
applicationWillTerminate(_:)
But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because the app isn't running.
On an iPad, if the app does support multiple windows
If the scene was frontmost:
sceneDidEnterBackground
applicationWillTerminate(_:) (perhaps)
But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because either the app isn't running or the app isn't terminating (if there's another window). If the app is still running, you might get sceneDidDisconnect(_:) and possibly application(_:didDiscardSceneSessions:) later.
Conclusions
What's the odd-man-out here? It's the case where we're running on an iPad and we support scenes but not multiple windows. We don't get sceneDidEnterBackground! I regard that as incoherent. Since we don't support multiple windows, this is basically an iPhone app and it should behave like an iPhone app. I shouldn't have to double up my code just because my app runs on both iPhone and iPad.
in my case, I want to save user state when the app is terminated by the user or the system, applicationWillTerminate(_:) does not being called for me most of the time.
I achieved what I want by using sceneWillResignActive(_ scene: UIScene)
I having a problem with the application life in iOS programming. My application has the view controller that has been subclassed for drawing. Everything went fine till I decide that went the app go inactive (Press Home). I want it to load a new screen. I used notifications of applicationWillEnterForeground and a few others. What happens the drawing code fails when I try to get the UIGraphicsGetCurrentContext, it comes back as nil. I assume I am attempting to get the context before it is available. What is the proper event. I think I tried all but the right one.
In my app I use iphone camera, but the process is very low when I open it; then I want to start the process when I shows a splashscreen.
The problem is that when splashscreen ends I don't want to show camera.
Then while I show splashscreen I want to start process of camera and quit it before splashscreen disappear. Is it possible?
First up, Apple specifically advise against using splash screens in their Human Interface Guidelines document. I don't know if your app would get rejected for it, but best not to try.
Second, it sounds like you need to optimise the startup of your application and probably the first view controller. To do this, you need to put off loading/initialising everything you can until it's actually needed (known as "lazy initialisation). All code in applicationDidFinishLaunching: in your app delegate and your view controller's init method, loadView, viewDidLoad, viewWillAppear, viewDidAppear should be reviewed for stuff that could be done later.
I have been creating a new iPad application based on the SplitViewController. I have modeled the app after the MultipleDetailViews sample app from Apple. The problem I have is that the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: method is not called at startup when the device starts in Portrait mode. This method is called during the startup sequence in the MultipleDetailViews sample app. It is during this call that the button to be presented in the toolbar in the main view should be added.
My application is working fine otherwise, i.e. I get the UISplitViewControllerDelegate calls in every other case. I can't figure out though why I am not getting the willHideViewController message during startup.
Any thoughts? Is there some other way I can get at the button to be displayed in the toolbar when starting in portrait mode if not through this willHideViewController message?
Thanks in advance,
-Eric