Skip to content

Commit

Permalink
Made osx app
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Coomans committed Feb 23, 2014
1 parent 0c0925f commit 8a1c1f5
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 336 deletions.
2 changes: 2 additions & 0 deletions SimulatorRemoteNotifications.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
51C4958418B9B4720062E968 /* ACAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 51C4958318B9B4720062E968 /* ACAppDelegate.m */; };
51C4958718B9B4720062E968 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51C4958518B9B4720062E968 /* MainMenu.xib */; };
51C4958918B9B4720062E968 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 51C4958818B9B4720062E968 /* Images.xcassets */; };
51C495A118B9C93F0062E968 /* libSimulatorRemoteNotifications-OSX.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 517C989918B801C800FC4694 /* libSimulatorRemoteNotifications-OSX.a */; };
51D01CB718B9A6A1001997E0 /* UIApplication+SimulatorRemoteNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 51741966173A167E0073FF2B /* UIApplication+SimulatorRemoteNotifications.m */; };
51D01CB818B9A6A1001997E0 /* ACSimulatorRemoteNotificationsService.m in Sources */ = {isa = PBXBuildFile; fileRef = 51D01CB618B9A65F001997E0 /* ACSimulatorRemoteNotificationsService.m */; };
51D01CBE18B9A73C001997E0 /* SimulatorRemoteNotifications-Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 51D01CBD18B9A73C001997E0 /* SimulatorRemoteNotifications-Prefix.pch */; };
Expand Down Expand Up @@ -175,6 +176,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
51C495A118B9C93F0062E968 /* libSimulatorRemoteNotifications-OSX.a in Frameworks */,
51C4957518B9B4720062E968 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 3 additions & 1 deletion iOS Simulator Notifications/ACAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface ACAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, assign) IBOutlet NSWindow *window;
@property (nonatomic, assign) IBOutlet NSTextView *payloadTextView;
@property (nonatomic, assign) IBOutlet NSTextField *errorTextField;

@end
68 changes: 65 additions & 3 deletions iOS Simulator Notifications/ACAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,73 @@

#import "ACAppDelegate.h"

#import "ACSimulatorRemoteNotificationsService.h"


static NSString * const ACAppDelegatePayloadUserDefaultsKey = @"ACAppDelegatePayloadUserDefaultsKey";

@implementation ACAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSDictionary *payload = [[NSUserDefaults standardUserDefaults] objectForKey:ACAppDelegatePayloadUserDefaultsKey];

if (![payload isKindOfClass:NSDictionary.class]) {
[self resetAction:self];
} else {
NSData *data = [NSJSONSerialization dataWithJSONObject:payload options:NSJSONWritingPrettyPrinted error:nil];
if (data) {
self.payloadTextView.string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
}
}

#pragma mark - Actions

- (IBAction)resetAction:(id)sender {

NSDictionary *dict = @{
@"aps" : @{
@"alert" : @"You got your emails.",
@"badge" : @9,
@"sound" : @"bingbong.aiff"
},
@"acme1" : @"bar",
@"acme2" : @42
};

NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
self.payloadTextView.string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

- (IBAction)sendAction:(id)sender {

self.errorTextField.hidden = YES;

NSError *error;

NSData *data = [self.payloadTextView.string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *payload = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

if (!payload) {
self.errorTextField.stringValue = [NSString stringWithFormat:@"Invalid JSON: %@", error.localizedFailureReason];
self.errorTextField.hidden = NO;
return;
}

if (![payload isKindOfClass:NSDictionary.class]) {
self.errorTextField.stringValue = @"Invalid JSON: Not a dictionary";
self.errorTextField.hidden = NO;
return;
}

// reformat payload
data = [NSJSONSerialization dataWithJSONObject:payload options:NSJSONWritingPrettyPrinted error:&error];
self.payloadTextView.string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

[[ACSimulatorRemoteNotificationsService sharedService] send:payload];

[[NSUserDefaults standardUserDefaults] setObject:payload forKey:ACAppDelegatePayloadUserDefaultsKey];
}

@end
Loading

0 comments on commit 8a1c1f5

Please sign in to comment.