Class: GKScore

Inherits:
NSObject show all

Overview

A GKScore class holds information for a score that was earned by the player. Your game creates GKScore objects to post scores to a leaderboard on Game Center. When your game retrieves score information from a leaderboard, those scores are returned as GKScore objects.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (String) category

The leaderboard that this score belongs to. The category string must match an identifier for a leaderboard you created on iTunes Connect.

Returns:

- (Integer) context

An integer value used by your game. The context property is stored and returned to your game, but is otherwise ignored by Game Center. It allows your game to associate an arbitrary 64-bit unsigned integer value with the score data reported to Game Center. You decide how this integer value is interpreted by your game. For example, you might use the context property to store flags that provide game-specific details about a player’s score, or you might use the context as a key to other data stored on the device or on your own server. The context is most useful when your game displays a custom leaderboard user interface.

Returns:

- (NSDate) date (readonly)

The date and time when the score was earned. (read-only) When you initialize the new score object, the date property is automatically set to the current date and time.

Returns:

- (String) formattedValue (readonly)

Returns the player’s score as a localized string. (read-only) This property is invalid on a newly initialized score object. On a score returned from Game Kit, it contains a formatted string based on the player’s score. You determine how a score is formatted when you define the leaderboard on iTunes Connect.Never convert the value property into a string directly; always use this method to receive the formatted string.

Returns:

- (String) playerID (readonly)

The player identifier for the player that earned the score. (read-only) When you initialize a new score object, the playerID property is set to the identifier for the local player. If the score object was returned to your game by loading scores from Game Center, the playerID property identifies the player who recorded that score.

Returns:

- (Integer) rank (readonly)

The position of the score in the results of a leaderboard search. (read-only) The value of this property is only valid on score objects returned from Game Center. The rank property represents the position of the score in the returned results, with 1 being the best score, 2 being the second best, and so on.

Returns:

- (Boolean) shouldSetDefaultLeaderboard

A Boolean value that indicates whether this score should also update the default leaderboard. If the value of this property is YES, when the score is reported to Game Center, Game Center also updates the local player’s default leaderboard to match the value stored in the category property of the score object. This matches the behavior of the GKLeaderboard class’s setDefaultLeaderboard:withCompletionHandler: class method. If the value of this property is NO, the default leaderboard is not changed by reporting the score. The default value of this property is NO.

Returns:

  • (Boolean)

- (Integer) value

The score earned by the player. You can use any algorithm you want to calculate scores in your game. Your game must set the value property before reporting a score, otherwise an error is returned.The value provided by a score object is interpreted by Game Center only when formatted for display. You determine how your scores are formatted when you define the leaderboard on iTunes Connect.

Returns:

Class Method Details

+ (Object) reportScores(scores, withCompletionHandler:completionHandler)

Reports a list of scores to Game Center Use this class method whenever you need to submit multiple scores at the same time. Calling this method reports each of the scores, exactly as if you called the reportScoreWithCompletionHandler: method on each score object in the array. However, the entire operation can typically be processed more efficiently using this method, and the completion handler is only called once.

Parameters:

  • scores (Array)

    An array of score objects to report to Game Center.

  • completionHandler (Object)

    A block to be called after the score is reported.The block receives the following parameter:errorIf an error occurred, this parameter holds an error object that describes the problem. If the score was successfully reported, this parameter’s value is nil.

  • error (NSError *error)

    If an error occurred, this parameter holds an error object that describes the problem. If the score was successfully reported, this parameter’s value is nil.

Returns:

Instance Method Details

- (Object) initWithCategory(category)

Returns an initialized score object. Your game explicitly allocates and initializes a score object when it needs to report a new score to Game Center.

Parameters:

  • category (String)

    An identifier for a specific leaderboard you’ve configured on iTunes Connect. Must not be nil.

Returns:

  • (Object)

    An initialized score object, or nil if an error occurred.

- (Object) issueChallengeToPlayers(playerIDs, message:message)

Issues a score challenge to a set of players. Your game should only issue a challenge request in direct response to a player action. That is, your game should provide a user interface that allows the player to choose to issue a challenge, and only issue a challenge when the player wishes to do so.

Parameters:

  • playerIDs (Array)

    An array of player identifiers for the players to challenge.

  • message (String)

    A text message to display to the players.

Returns:

- (Object) reportScoreWithCompletionHandler(completionHandler)

Reports a score to Game Center. The value property must be set before calling this method.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler (Object)

    A block to be called after the score is reported.The block receives the following parameter:errorIf an error occurred, this parameter holds an error object that describes the problem. If the score was successfully reported, this parameter’s value is nil.

  • error (NSError *error)

    If an error occurred, this parameter holds an error object that describes the problem. If the score was successfully reported, this parameter’s value is nil.

Returns: