我是 iPhone 开发的新手,但设法在我的 iOS 应用程序中接收推送通知。但是,当我刷掉传入的推送通知时,它只会打开应用程序,而不是通知的相关帖子。
这是我的代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"Eine Nachricht ist angekommen, während die App aktiv ist");
NSString* alert = [[userInfo objectForKey:@"aps"] objectForKey:@"id"];
NSLog(@"Nachricht: %@", alert);
//This is to inform about new messages when the app is active
//UIApplicationState state = [[UIApplication sharedApplication] applicationState];
//if (state == UIApplicationStateActive) {
// UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Neuer Artikel" message:@"Nachricht" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
// [alertView show];
// }
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Device Token=%@", deviceToken);
NSUInteger theCount = [deviceToken length];
NSMutableString *theString = [NSMutableString stringWithCapacity:2 * theCount];
unsigned char const *theBytes = [deviceToken bytes];
for(NSUInteger i = 0; i < theCount; ++i) {
[theString appendFormat:@"%2.2x", theBytes[i]];
}
NSString* url = [NSString stringWithFormat:@"HERE_IS_MY_REGISTERING_URL",theString,theString];
NSLog(@"APNS URL : %@",url);
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *urlResponse, NSData *data, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
}
}];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"Error bei der Registrierung");
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.frame = [[UIScreen mainScreen] bounds];
[self setApplicationDefaults];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
//This is the start of the push notification settings
[self.window makeKeyAndVisible];
现在,我不知道该放什么,打开一个推送通知的相关帖子......