m (→Faking push notification: Made code usable for all versions.) |
|||
Line 2: | Line 2: | ||
== Faking push notification == | == Faking push notification == | ||
Push notification may be faked locally these ways: | Push notification may be faked locally these ways: | ||
<source lang="objc"> | <source lang="objc"> | ||
NSDictionary *userInfo = @{ @"aps" : @{ @"badge" = @5, @"alert" : @"hi" } }; | NSDictionary *userInfo = @{ @"aps" : @{ @"badge" = @5, @"alert" : @"hi" } }; | ||
NSString *topic = @"com.yourcompany.appname"; | NSString *topic = @"com.yourcompany.appname"; | ||
// pre iOS 7 | if (kCFCoreFoundationVersionNumber < 800.0) { // pre iOS 7 | ||
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo]; | [[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo]; | ||
} else { // iOS 7+ | |||
// iOS 7+ | APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo]; | ||
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo]; | [[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message]; | ||
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message]; | [message release]; | ||
[message release]; | } | ||
</source> | </source> | ||
Revision as of 01:57, 1 June 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";
if (kCFCoreFoundationVersionNumber < 800.0) { // pre iOS 7
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo];
} else { // iOS 7+
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
[message release];
}
References