forked from typeoneerror/GKAchievementNotification
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGKAchievementHandler.m
More file actions
executable file
·142 lines (112 loc) · 3.39 KB
/
GKAchievementHandler.m
File metadata and controls
executable file
·142 lines (112 loc) · 3.39 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// 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];
}
/** when in landscape mode, adding notification view to the topview is the easiest way to get the nofitication displayed in landscape mode instead of setting view.transform manually */
if(_keyWindow.rootViewController) {
[_keyWindow.rootViewController.view addSubview:notification];
}
else {
[_keyWindow 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)
{
_keyWindow = [[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];
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];
notification.handlerDelegate = self;
[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}
- (void)notifyAchievementTitleAndIcon:(NSString *)title andMessage:(NSString *)message withIcon:(UIImage*)icon {
GKAchievementNotification *notification = [[GKAchievementNotification alloc] initWithTitle:title andMessage:message];
notification.handlerDelegate = self;
[notification setImage:icon];
[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}
- (void)notifyAchievementTitleAndIcon:(GKAchievementNotification*)notification {
[_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