Difference between revisions of "SBRemoteNotificationServer"

From iPhone Development Wiki
Jump to: navigation, search
m (Created page with 'SBRemoteNotificationServer is a singleton class that receives Apple push notifications. == Faking push notification == Push notification may be faked locally using the -conn…')
 
(Faking push notification: Updated for iOS 8.)
Line 2: Line 2:
  
 
== Faking push notification ==
 
== Faking push notification ==
Push notification may be faked locally using the -connection:didReceiveMessageForTopic:userInfo: method, like this:
+
Push notification may be faked locally these ways:
 
<source lang="objc">
 
<source lang="objc">
static const char plist[] = "{aps={badge=5;alert=hi;};etc=foo;}";
+
NSDictionary *userInfo = @{ @"aps" : @{ @"badge" = @5, @"alert" : @"hi" } };
NSDictionary* userInfo = [NSPropertyListSerialization propertyListFromData:[NSData dataWithBytesNoCopy:plist length:sizeof(plist) freeWhenDone:NO]
+
NSString *topic = @"com.yourcompany.appname";
                                                          mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:NULL];
+
 
[[SBRemoteNotificationServer sharedInstance] connection:nil didReceiveMessageForTopic:@"com.yourcompany.appname" userInfo:userInfo];
+
// pre iOS 8
 +
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo];
 +
 
 +
// iOS 8
 +
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
 +
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
 +
[message release];
 
</source>
 
</source>
  

Revision as of 07:30, 31 May 2015

SBRemoteNotificationServer is a singleton class that receives Apple push notifications.

Faking push notification

Push notification may be faked locally these ways:

NSDictionary *userInfo = @{ @"aps" : @{ @"badge" = @5, @"alert" : @"hi" } };
NSString *topic = @"com.yourcompany.appname";

// pre iOS 8
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo];

// iOS 8
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
[message release];

References