Ios 滑动推送通知应打开相关新闻

Ios 滑动推送通知应打开相关新闻,ios,apple-push-notifications,Ios,Apple Push Notifications,我是iPhone开发新手,但在iOS应用程序中成功接收推送通知。但是,当我刷走传入的推送通知时,它只会打开应用程序,而不会打开通知的相关帖子 这是我的代码: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSLog(@"Eine Nachricht ist angekommen, während die App aktiv ist");

我是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];
-(void)应用程序:(UIApplication*)应用程序DidReceiveMemoteNotification:(NSDictionary*)用户信息{
NSLog(@“这是一个很好的例子,也是一个很好的例子”);
NSString*alert=[[userInfo objectForKey:@“aps”]objectForKey:@“id”];
NSLog(@“Nachricht:%@),警报);
//这是为了在应用程序处于活动状态时通知新消息
//UIApplicationState=[[UIApplication sharedApplication]applicationState];
//如果(状态==UIApplicationStateActive){
//UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“Neuer Artikel”消息:@“Nachricht”委托:无取消按钮提示:@“确定”其他按钮提示:无];
//[警报视图显示];
//    }
}
-(无效)应用程序:(UIApplication*)应用程序DIdRegisterForRemotionTificationswithDeviceToken:(NSData*)deviceToken{
NSLog(@“设备令牌=%@”,deviceToken);
NSU整数计数=[deviceToken length];
NSMutableString*字符串=[NSMutableString stringWithCapacity:2*计数];
无符号字符常量*字节=[deviceToken字节];
对于(整数i=0;i

现在,我不知道该把什么放在哪里,打开一个推送通知的相关帖子…

你期望什么?从你的代码中,我看不出你提供了任何关于要打开哪个帖子的信息。苹果、Xcode或你的代码都不会知道这一点

在推送通知的有效负载中,您必须提供您所指的帖子的信息,然后在您的DidReceiveMotonification中阅读此信息


请参阅此处的“JSON有效负载示例:

以及在DidReceiveMemoteNotification中读取它的代码是什么?就像您正在阅读它的aps部分一样:您现在使用的是
NSString*alert=[userInfo objectForKey:@“aps”];
,您将使用
id myInfo=[userInfo objectForKey:@“acme”]
,为了留在苹果的例子中,我简单地用上面提到的字符串替换这个字符串?是的。如果您的有效负载是:
{“aps”:{“alert”:“New Post”,},“postid”:“424242”}˚
,那么您就可以用
NSString*postid=[userInfo objectForKey:@“postid]”获得postid;