Difference between revisions of "SBRemoteNotificationServer"

From iPhone Development Wiki
Jump to: navigation, search
m
m (Faking push notification: Correction location of message releasing.)
 
(3 intermediate revisions by 3 users not shown)
Line 10: Line 10:
 
// topic must be an existing application identifier, or notification won't show.
 
// topic must be an existing application identifier, or notification won't show.
  
if (kCFCoreFoundationVersionNumber < 800.0) { // pre iOS 7
+
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
 +
 
 +
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) {
APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];
+
// iOS 7/8
 
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
 
[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
[message release];
+
} else if (kCFCoreFoundationVersionNumber < 1300) {
 +
// iOS 9
 +
UNUserNotificationServer *userNotificationServer = [%c(UNUserNotificationServer) sharedInstance];
 +
UNNotificationRegistrarConnectionListener *registrarConnectionListener = MSHookIvar<UNNotificationRegistrarConnectionListener *>(userNotificationServer, "_registrarConnectionListener");
 +
UNRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNRemoteNotificationServer *>(registrarConnectionListener, "_removeNotificationServer");
 +
[remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
 
}
 
}
 +
else {
 +
// iOS 10
 +
UNSUserNotificationServer *userNotificationServer = [%c(UNSUserNotificationServer) sharedInstance];
 +
UNSRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNSRemoteNotificationServer *>(userNotificationServer, "_remoteNotificationService");
 +
[message setTimestamp:[NSDate date]]; // required on iOS 10
 +
[remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
 +
}
 +
[message release];
 
</source>
 
</source>
  

Latest revision as of 00:37, 20 July 2017

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.

APSIncomingMessage *message = [[%c(APSIncomingMessage) alloc] initWithTopic:topic userInfo:userInfo];

if (kCFCoreFoundationVersionNumber < 800.0) {
	// pre iOS 7
	[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveMessageForTopic:topic userInfo:userInfo];
}  else if (kCFCoreFoundationVersionNumber < 1200) {  
	// iOS 7/8
	[[%c(SBRemoteNotificationServer) sharedInstance] connection:nil didReceiveIncomingMessage:message];
} else if (kCFCoreFoundationVersionNumber < 1300) { 
	// iOS 9
	UNUserNotificationServer *userNotificationServer = [%c(UNUserNotificationServer) sharedInstance];
	UNNotificationRegistrarConnectionListener *registrarConnectionListener = MSHookIvar<UNNotificationRegistrarConnectionListener *>(userNotificationServer, "_registrarConnectionListener");
	UNRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNRemoteNotificationServer *>(registrarConnectionListener, "_removeNotificationServer");
	[remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
}
else {
	// iOS 10
	UNSUserNotificationServer *userNotificationServer = [%c(UNSUserNotificationServer) sharedInstance];
	UNSRemoteNotificationServer *remoteNotificationServer = MSHookIvar<UNSRemoteNotificationServer *>(userNotificationServer, "_remoteNotificationService"); 
	[message setTimestamp:[NSDate date]]; // required on iOS 10
	[remoteNotificationServer connection:nil didReceiveIncomingMessage:message];
}
[message release];

References