Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
SBRemoteNotificationServer: Difference between revisions - iPhone Development Wiki

SBRemoteNotificationServer: Difference between revisions

From iPhone Development Wiki
mNo edit summary
Line 12: Line 12:
if (kCFCoreFoundationVersionNumber < 800.0) { // 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+
} else if (kCFCoreFoundationVersionNumber < 1200) {
// iOS 7/8
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];
} else {
        // iOS 9
        UNUserNotificationServer *userNotificationServer = [%c(UNUserNotificationServer) sharedInstance];
UNNotificationRegistrarConnectionListener *registrarConnectionListener = MSHookIvar<UNNotificationRegistrarConnectionListener *>(userNotificationServer, "_registrarConnectionListener");
UNRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNRemoteNotificationServer *>(registrarConnectionListener, "_removeNotificationServer");
        [remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
}
}
</source>
</source>

Revision as of 21:11, 19 December 2016

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";
// topic must be an existing application identifier, or notification won't show.

if (kCFCoreFoundationVersionNumber < 800.0) { // pre iOS 7
	[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo];
}  else if (kCFCoreFoundationVersionNumber < 1200) {  
	// iOS 7/8
	APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
	[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
	[message release];
} else { 
        // iOS 9 
        UNUserNotificationServer *userNotificationServer = [%c(UNUserNotificationServer) sharedInstance];
	UNNotificationRegistrarConnectionListener *registrarConnectionListener = MSHookIvar<UNNotificationRegistrarConnectionListener *>(userNotificationServer, "_registrarConnectionListener");
	UNRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNRemoteNotificationServer *>(registrarConnectionListener, "_removeNotificationServer");
        [remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
}

References