如何在iPhone应用程序中接收推送通知消息?

发布于 2024-11-19 17:02:10 字数 2793 浏览 2 评论 0原文

步骤创建了 .pem 文件

  1. 我按照登录 iPhone 开发者计划门户的
  2. 。从右侧菜单中选择应用程序 ID。
  3. 创建不带通配符的应用程序 ID。
  4. 单击此应用程序 ID 旁边的配置链接,然后单击按钮启动向导以生成新的开发推送 SSL 证书。
  5. 下载此证书并双击 aps_developer_identity.cer 将其导入您的钥匙串
  6. 启动钥匙串助手,然后单击左侧的我的证书
  7. 展开 Apple IOS 开发推送服务并选择 Apple IOS 开发推送服务和我的私钥
  8. 右键单击并选择“导出 2 个元素...”并保存为 cert.p12。
  9. 打开终端并将目录更改为用于保存 cert.p12 的位置,并使用此命令将 PKCS12 证书包转换为 PEM 格式 openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts 10.现在我使用这个 PEM 文件作为 ApnsPHP 中的证书!

当我在浏览器中使用它显示的网址时; {"aps":{"alert":"hi","badge":1,"sound":"beep.wav"}}

我正在使用此代码在 iphone 应用程序中接收通知

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];


    NSLog(@"\n\n\n\nRegistering for push notifications...\n\n\n\n");    
    [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound)];

}


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"\n\n\n\n\n device token===%@\n\n\n\n",token);
    //DeviceRegisterer *registrar = [[DeviceRegisterer alloc] init];
    //[registrar registerDeviceWithToken:token];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"failed to regiser %@", err);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog(@"notification options %@", userInfo);

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Super" message:@"welcome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    for (id key in userInfo) {


        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        myTextField.text = [userInfo objectForKey:key];
        [myAlertView addSubview:myTextField];
        [myAlertView show];
        [myAlertView release];

    }    

}

,但无法接收通知信息。 请帮助解决这个问题。

提前致谢, 森希尔库马尔

I created .pem file following steps

  1. Log-in to the iPhone Developer Program Portal.
  2. Choose App IDs from the menu on the right.
  3. Create an App ID without a wildcard.
  4. Click the Configure link next to this App ID and then click on the button to start the wizard to generate a new Development Push SSL Certificate.
  5. Download this certificate and double click on aps_developer_identity.cer to import it into your Keychain
  6. Launch Keychain Assistant and click on My Certificates on the left
  7. Expand Apple IOS Development Push Services and select Apple IOS Development Push Services AND my private key
  8. Right-click and choose "Export 2 elements..." and save as cert.p12.
  9. Open Terminal and change directory to location used to save cert.p12 and convert the PKCS12 certificate bundle into PEM format using this command
    openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
    10.Now i use this PEM file as my certificate in ApnsPHP!

while i use the url in the browser it display; {"aps":{"alert":"hi","badge":1,"sound":"beep.wav"}}

I am using this code to receive notification in iphone app

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];


    NSLog(@"\n\n\n\nRegistering for push notifications...\n\n\n\n");    
    [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound)];

}


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"\n\n\n\n\n device token===%@\n\n\n\n",token);
    //DeviceRegisterer *registrar = [[DeviceRegisterer alloc] init];
    //[registrar registerDeviceWithToken:token];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"failed to regiser %@", err);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog(@"notification options %@", userInfo);

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Super" message:@"welcome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    for (id key in userInfo) {


        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        myTextField.text = [userInfo objectForKey:key];
        [myAlertView addSubview:myTextField];
        [myAlertView show];
        [myAlertView release];

    }    

}

But am not able to receive the notification message.
Please help to resolve this problem.

Thanks in advance,
Senthilkumar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来是傀儡 2024-11-26 17:02:10

您没有使用服务器来发送消息。 pem 密钥供服务器用来发送消息。我认为你不能使用你的 iPhone 应用程序直接发送推送消息。
如果您的服务器使用 PHP,请尝试在此站点中查找用于发送通知的代码。
注意:在我的服务器上,ApnsPHP 代码根本不起作用,我使用 stackOverflow 中找到的一个简单的 php 脚本(抱歉不记得链接)来管理它并起作用。

You are not using a server to send the message. The pem key is meant to be used by a server to send the message. I think that you cannot use your iphone app to send directly a push message.
If your server is using php try to find in this site the code to delivery the notifications.
Note: On my server the ApnsPHP code do not work at all, I used a simple php script found in stackOverflow (sorry do not remember the link) to manage it and works.

情域 2024-11-26 17:02:10

我解决了这个问题。 php .pem 文件攻击中出现问题。感谢您提供的想法。

I solved this problem. Problem in the php .pem file attactment . thanks for gave idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文