This repository has been archived by the owner on Nov 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
GKAchievementHandler.m
117 lines (91 loc) · 2.55 KB
/
GKAchievementHandler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// GKAchievementHandler.m
//
// Created by Benjamin Borowski on 9/30/10.
// Copyright 2010 Typeoneerror Studios. All rights reserved.
// $Id$
//
#import <GameKit/GameKit.h>
#import "GKAchievementHandler.h"
#import "GKAchievementNotification.h"
static GKAchievementHandler *defaultHandler = nil;
#pragma mark -
@interface GKAchievementHandler(private)
- (void)displayNotification:(GKAchievementNotification *)notification;
@end
#pragma mark -
@implementation GKAchievementHandler(private)
- (void)displayNotification:(GKAchievementNotification *)notification
{
if (self.image != nil)
{
[notification setImage:self.image];
}
else
{
[notification setImage:nil];
}
[_topView addSubview:notification];
[notification animateIn];
}
@end
#pragma mark -
@implementation GKAchievementHandler
@synthesize image=_image;
#pragma mark -
+ (GKAchievementHandler *)defaultHandler
{
if (!defaultHandler) defaultHandler = [[self alloc] init];
return defaultHandler;
}
- (id)init
{
self = [super init];
if (self != nil)
{
_topView = [[UIApplication sharedApplication] keyWindow];
_queue = [[NSMutableArray alloc] initWithCapacity:0];
self.image = [UIImage imageNamed:@"gk-icon.png"];
}
return self;
}
- (void)dealloc
{
[_queue release];
[_image release];
[super dealloc];
}
#pragma mark -
- (void)notifyAchievement:(GKAchievementDescription *)achievement
{
GKAchievementNotification *notification = [[[GKAchievementNotification alloc] initWithAchievementDescription:achievement] autorelease];
notification.frame = kGKAchievementFrameStart;
notification.handlerDelegate = self;
[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}
- (void)notifyAchievementTitle:(NSString *)title andMessage:(NSString *)message
{
GKAchievementNotification *notification = [[[GKAchievementNotification alloc] initWithTitle:title andMessage:message] autorelease];
notification.frame = kGKAchievementFrameStart;
notification.handlerDelegate = self;
[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}
#pragma mark -
#pragma mark GKAchievementHandlerDelegate implementation
- (void)didHideAchievementNotification:(GKAchievementNotification *)notification
{
[_queue removeObjectAtIndex:0];
if ([_queue count])
{
[self displayNotification:(GKAchievementNotification *)[_queue objectAtIndex:0]];
}
}
@end