Cannot receive friend invites in Game center - ios

I'm creating a live multiplayer game with 2 players through game center.
I followed Ray Wenderlich's tutorial on game center and I tried to set up the invite friends. I set up the call back just like apple said:
if ([GKLocalPlayer localPlayer].isAuthenticated) {
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
NSLog(#"Received invite");
self.pendingInvite = acceptedInvite;
self.pendingPlayersToInvite = playersToInvite;
[self inviteReceived];
};
}
I even tested whether the block property is actually set. It is.
I'm in sandbox with a simulator and an iPhone 5 both at iOS7. I couldn't receive ANY invitations (see screenshot). I enabled notification center, checked accept invitation in settings, but the block is never called. Random match worked fine though.

Solved it by borrowing someone else's device instead of using the simulator.

Related

Trying to Write An Auto Answer App to Test iPhone

I'm trying to write an app to auto answer an iphone when there are incoming calls.
The app can be launched by the user and run in the background.
I'm trying to use the IOS Private APIs to do this, but no success.
This is for testing purpose only and won't be submitted to the app store so using private APIs shouldn't be a problem. The phones aren't jailbroken though.
This is what I have in my AppDelegate.m file (didFinishLaunchingWithOptions):
id callCenterId = [TUCallCenter sharedInstance];
NSLog(#"callCenterId: %#", callCenterId);
TUCallCenter *object = [[TUCallCenter alloc] init];
NSLog(#"object: %#", object);
[object handleCallModelStateChanged: ^{
NSLog(#"this is an incoming call");
}];
When I run the app, I do see some outputs in the debug panel:
2016-02-01 10:32:38.849 AutoAnswer[312:63056] callCenterId: <TUCallCenter: 0x134642b40>
2016-02-01 10:32:38.851 AutoAnswer[312:63056] object: <TUCallCenter: 0x1346496c0>
But nothing is shown when I dial the phone when the app is in the foreground. I can't even get that to work, so forget about making it work in the background.
Any help would be appreciated.

Xcode - Admob banner setting with targeting and test devices

I am working on my iOS app and trying to place a banner on the bottom of the page.
First of all, I set a BOOL (BannerAd) which is initially "NO" and set to "YES" when user hits the "Submit" button. By doing this tried to avoid requesting ads eveytime the user hit "Submit". This seems to work but world be nice if you can comment on it.
My interface has a "Datepicker" where the user selects his/her Birthday. I wanted to use this information for ad targeting. Also I know my application will be used in "Germany" so I set the location manually to "Germany" since my app doesn't request location information from user. And finally I am trying to test my app on my device where I set my test device UDID in "testDevices"
My problem is, I think my requests don't work. When I enter my own "adUnitId", I get paid ads on my device (which may cause a problem). Also when I tried to change the location, for example to "France", I still get local ads. I guess my location is not working and AdMob is using the network to determine the location. Which makes me think my "Birthday" information isn't working, too.
Below is the code I use and I don't know which part is wrong. I did researched and did everything according to the guides. I am not experienced and hoped that you guys can help me out!
Appreciated!
// Show Banner Ad
if (BannerAd == NO)
{
self.bannerView.adUnitID = #"ca-app-pub-3940256099942544/2934735716"; // TEST ID
self.bannerView.rootViewController = self;
NSDate *birthday =[datepick date];
GADRequest *request = [GADRequest request];
[request setBirthday: birthday];
[request setLocationWithDescription:#"Germany"];
request.testDevices = #[ #"b23cbd41317324cd9afd14dc848f2f0e" // TEST DEVICE
];
[self.bannerView loadRequest:[GADRequest request]];
BannerAd = YES;}
I can't understand your question(s) so good. Sorry.
If you want to put your adMob banner on the bottom of the screen, just use:
bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,self.view.frame.size.height - 50, self.view.frame.size.width, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height)];

Implement my own a custom GKTurnBasedMatchmakerViewController

I'm sure there are questions similar to this, but I couldn't find an example. I'm trying to recreate the apple GKTurnBasedMatchmakerViewController for my turn based game with my own custom interface for my turn based iphone game. I'm having trouble getting all the options to display correctly so I was hoping someone had a working example. My current code is this:
-(void)getCurrentGamesFromServer {
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {
if(matches){
for (GKTurnBasedMatch *myMatch in matches) {
//this is, I believe, also where we need to consider invitations. available instance methods provided by GC are: acceptInviteWithCompletionHandler and declineInviteWithCompletionHandler
if(myMatch.status == 1){ //ongoing game
if([myMatch.currentParticipant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]){ //if it's my turn
//here we need to populate the table by adding our matches to mcurrentgamesarray. after all the matches have been added, reload the tableview
NSLog(#"active game that is my turn");
[self.mCurrentGamesArray addObject:myMatch];
}
else{
NSLog(#"other turn or an invite from another player waiting to hear from you");
}
}
}
}
[_mCurrentGamesTableView reloadData];
}];
}
As you can see, the only games I'm grabbing right now are games where the status is 1 (ongoing game) and the current participant ID is my ID.
to get games that were not my turn, I tried doing games where it was not my ID, but it included invites with it and I couldn't figure out how to separate them out.
Basically, I'd like to have a section of games where it is my turn, a section where it is not my turn but games are still active, a section of completed old games, and a section for invites. does anyone have a working example, or a page they can send me to that explains the best practices for what I'm trying to do? Thanks for your help.

Gamekit / gamecenter random matchmaking programmatically

I am trying to implement random matchmaking programmatically with my own custom userinterface.
I'm kinda stuck..
using this code found at the apple site I can create a match without problems
- (void)findProgrammaticMatch
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest: request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
if(error)
NSLog(#"ERROR");
if (match) {
NSLog(#"STARTING MATCH");
}
}];
}
and if I do match.participants.count I get the number 2...
but one participant is me and the other is null
What ive done to test is create 2 sandbox accounts and I ran the same code with my other game center account, and I got a new game created,.. but it didnt match them for some reason.. am I missing something?
ive been looking for examples on google, but I can't seem to find any.. if any of you know anywhere I can find some examples, I would be most grateful
Well, you might be missing out an essential point in turn based match making. When the user starts an automatch if he is not connected to an existing match it starts a fresh game and user takes the first turn. Only after HE COMPLETES HIS TURN, other users can connect to this game. So if you are making a 2 player match: one user should start a fresh game with the other user being null at that moment and the other user should connect to this existing game after the first one finished his turn (endTurnWithMatchData called)
This is not very clear in documentation (I despise the gamecenter documentation, unclear & incomplete) but it is the case for sdk 6. I think it will change in the near future.

ios can players form teams of 2 and play other teams of 2 in game center [duplicate]

I have a "Play Now" button in my app that allows players to be auto-matched with other random players. Maybe I'm missing this somewhere in the docs, but how do I write the code to auto match players?
The Game Center sandbox server has been messed up the last few days, so I'm having a hard time trying different things since I have to guess because the Game Kit docs aren't exactly clear on how to do this. Currently, I have code setup (but untested) to create a match with a friend...
NSArray *playerList = [NSArray arrayWithObject:pid];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 4;
request.playersToInvite = playerList;
[[self waitingIndicator] startAnimating];
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error)
{
//handle error
}
else if (match != nil)
{
self.myMatch = match;
//start match code
}
}];
But how do I auto match two random people looking for a game? My guess, since the docs don't say it, or I'm missing it, is that in order to create an auto match, I simply set the playersToInvite property of the match object to nil? If not, how do I create an auto match?
One other question, while we're on the topic, the Game Kit docs site a few common matchmaking scenarios, one of them being...
A player can also create a network
match using the Game Center
application. When they invite a friend
into a multiplayer game, your
application is launched on both
devices, and each copy of your
application receives an invitation to
join the game.
But I can't figure out how to do this in the Game Center app for testing purposes. How does a user create a network match using the Game Center app? I don't see any buttons for that anywhere in the Game Center app.
Thanks in advance for your wisdom!
Ok, now that the sandbox Game Center server is back up, I was able to confirm that auto-matching works by setting the playersToInvite property to nil, or not setting it all.

Resources