Ste*_*nig -2 apple-push-notifications ios
我是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];
Run Code Online (Sandbox Code Playgroud)
现在,我不知道该放什么地方,打开推送通知的相关帖子......
你能指望什么?从您的代码中,我无法看到您提供有关您要打开哪个帖子的任何信息.Apple,Xcode或您的代码都不会通过魔法知道.
在推送通知的有效负载中,您必须提供您所引用的帖子的信息,然后在didReceiveRemoteNotification中阅读此信息.
请参阅:"JSON Payloads示例":Apple推送通知服务
| 归档时间: |
|
| 查看次数: |
1054 次 |
| 最近记录: |