Implement my own a custom GKTurnBasedMatchmakerViewController - ios

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.

Related

Deezer iOS SDK - Play specific track from radio

I'm currently working with Deezer SDK to play a radio from deezer in my app.
Is possible to play a radio even if the user has not authorized my app.
Is there a way to play a specific track from a Radio?
I'm following this guide but it seems that this was possible in the old Sdk but not in the new.
In the old sdk there were also more Delegate methods such as
- (void)player:(PlayerFactory *)player timeChanged:(long)time
But my main goal would be to play a track from a radio, in order to be sure to not play the same track two times in a row.
Is there someone that knows how to accomplish my goal?
It's possible to play a radio even you aren't connected if you want you can take a look here :
https://developers.deezer.com/sdk/ios#player
At the section « Play a
radio without user connected (New Api)
Of course you can play a specific track from a radio,
a radio is like, a playlist or an album, it's a DZRObjectList.
From your DZRObjectList, you can call :
- (void)allObjectsWithManager:(DZRRequestManager *)manager callback:(void (^)(NSArray *objs, NSError *error))callback;
Every object should be a track, so you can achieve your goal by making a check directly on the array.
Best Regards,
EDIT
This is an example :
DZRRadio *yourDZRRadio;
DZRRequestManager *manager = [[DZRRequestManager defaultManager] subManager];
[yourDZRRadio valueForKey:#"tracks" withRequestManager:manager callback:^(DZRObjectList *objectList, NSError *error) {
if (objectList != nil) {
[objectList allObjectsWithManager:manager callback:^(NSArray *tracks, NSError *error) {
/*
* Here you have tracks from your radio so you can send it to your player :)
*/
}];
} else {
}
}];

Getting all the user's friends that are using the app

I know that by the title this question has been asked a lot, but with the new Facebook 4.0 sdk this is a problem.
I know that if i call
[self FCMSendOpenGraphRequestWithPath:#"me/friends" andCompletionHandler:^(BOOL seccess, id result, NSError *error) {
if (seccess) {
}
}else{
}
}];
I will get all the user's friends that are using my app and that fit into one paging page (i have noticed that one page can hold 25 friends).
My problem is what happens when i need to get the page 2,3,4..etc'?
I know that if i call the graph call with the 'next' field i will get the next page. But because the Facebook sdk uses only completionHandlers using recursion won't work, and i don't want to hard code all the method call obviously.
All advices will help,
Thanks

SPPlaylist items as SPTracks not loading (consistently)

I've been struggling with this for a while now and was looking around for some advice from anyone who's worked with CocoaLibSpotify on iOS (iOS 7 to be exact).
I'm trying to load all the (SPTrack) items in a SPPlaylist. I've looked though the example code and the documentation so I know the best way to observe things is with KVO, however I can't see how that's the best way here.
Looking at the "Guess the Into" example and other sources on GitHub and the web in general, the precess I'm doing is as follows:
Get the SPPlaylist (this is either directly from a the users playlists or created from a saved URL),
Load the playlist with SPAsyncLoading,
Loop though the SPPlaylistItems returned in the SPPlaylist and get all the SPTrack objects,
Pass the array of SPTrack objects into another SPAsyncLoading call,
Display all items from the loadedItems array.
Step 5 is where things seem to go wrong. Sometimes it is fine and I get all the tracks in the playlist displaying. However most of the time it doesn't load them, or only load a few (normally very little).
I've noticed that restarting the phone can sometimes make it work. Though after running the app (or changing the playlist) a couple of time, it stops working again.
When I log each step I get something like the following:
-[ViewController sessionDidLoginSuccessfully:]
Load playlist with URL: spotify:user:XXXXX:playlist:XXXXXXXXXXXXXXXXXXXXXX
Created playlist: <SPPlaylist: 0x16775bc0>: (null) (0 items)
Loaded playlist: <SPPlaylist: 0x16775bc0>: Playlist Name (59 items)
Created SPTrack items: 59
Loaded SPTrack items: 1
Failed to load SPTrack items: 58
As you can see, the user is logged on, with a valid session. Each step works according to plan until the end. Sometimes even if it does load a track, it won't allow me to play it anyway as well returning SP_TRACK_AVAILABILITY_UNAVAILABLE.
I've also added a code snippet below if it helps. But any help would be grateful at this point with this.
Thanks.
- (void)loadPlaylist
{
__weak NSURL *spotifyURL = <URL from saved SPPlaylist>;
NSLog(#"Load playlist with URL: %#", spotifyURL);
[SPPlaylist playlistWithPlaylistURL:spotifyURL inSession:[SPSession sharedSession] callback:^(SPPlaylist *playlist) {
_spotifyPlaylist = playlist;
NSLog(#"Created playlist: %#", _spotifyPlaylist);
[SPAsyncLoading waitUntilLoaded: _spotifyPlaylist timeout:kSpotifyTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) {
NSLog(#"Loaded playlist: %#", _spotifyPlaylist);
if ([loadedItems count] > 0)
[self loadSpotifyPlaylist];
}];
}];
}
- (void)loadSpotifyPlaylist
{
NSArray *tracksArray = [self tracksFromPlaylistItems:[_spotifyPlaylist items]];
NSLog(#"Created SPTrack items: %d", [tracksArray count]);
if (tracksArray && [tracksArray count] > 0)
{
[SPAsyncLoading waitUntilLoaded:tracksArray timeout:kSpotifyTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) {
_playlist = loadedItems;
NSLog(#"Loaded SPTrack items: %d", [loadedItems count]);
NSLog(#"Failed to load SPTrack items: %d", [notLoadedItems count]);
[self finishReloadData];
}];
}
_spotifyPlaylist and _playlist are both strong instances and tracksFromPlaylistItems: is the same method used in the "Guess the Info" sample code.
Edit: The kSpotifyTimeout timeout is set to 10.0.
What's your value of kSpotifyTimeout? I think what you're seeing is simply the fact that metadata can take a long time to load (especially yesterday when the Spotify backend seemed to be having trouble, which can happen from time to time).
Generally, loading the entire contents of a playlist at once is bad practice, and you'll see that Guess the Intro doesn't actually care whether all the tracks loaded or not - it just grabs what happened to load and uses those tracks for the game.
A good approach to take is to paginate loading of playlist tracks to match your UI. That is, to only load the tracks your user can see, plus maybe a "screen" or two's worth up and down. As the user scrolls, you can start loading tracks - UIScrollViewDelegates -scrollViewWillEndDragging:withVelocity:targetContentOffset: is particularly good for this, as it lets you see where the user will "land" and start to load tracks for that point. There's some example code for doing this as well as a helper class called SPSparseArray for partially loading content like playlists on the dev branch of CococaLibSpotify (although be aware that dev branch = beta quality).

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