2014-05-20 01:37
浏览 82

如何在Amazon SNS(通知服务)中注册IOS设备令牌和接收消息?

I am working on a IOS project and I would like to integrate the SNS to my project without simply using APN.

All I need is:

Ask the user whether to receive notification
get device ID
Store device ID
Send to each device ID using PHP

Since I have work for GCM android before , I have some basic idea about this, I downloaded the sample app from Amazon, and I achieve the first two step, that means I can get the device ID, but the problem are

it did not automatically store on Amazon, Also, when I manually insert the id to Amazon and tried to send the message, it does not success

Here is the code:

IOS side (AppDelegate.m)

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    application.applicationIconBadgeNumber = 0;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
        NSString *msg = [NSString stringWithFormat:@"%@", launchOptions];
        [self createAlert:msg];
    return YES;

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
    NSLog(@"deviceToken: %@", deviceToken);

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{
    NSLog(@"Failed to register with error : %@", error);

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    application.applicationIconBadgeNumber = 0;
    NSString *msg = [NSString stringWithFormat:@"%@", userInfo];
    [self createAlert:msg];

- (void)createAlert:(NSString *)msg {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message Received" message:[NSString stringWithFormat:@"%@", msg]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];


PHP warning message when send the notification

Success: arn:aws:sns:ap-southeast-1:447163929286:endpoint/APNS_SANDBOX/tuen_mun_travel_sandbox/46a38bf8-3d1a-35f9-817a-62cd56b3c502

Warning: Cannot modify header information - headers already sent by (output started at /home/tuenmunt/public_html/wp-content/plugins/push.php:67) in /home/tuenmunt/public_html/wp-admin/post.php on line 233

Warning: Cannot modify header information - headers already sent by (output started at /home/tuenmunt/public_html/wp-content/plugins/push.php:67) in /home/tuenmunt/public_html/wp-includes/pluggable.php on line 896

Thanks for helping

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsrw29618
    dsrw29618 2014-10-12 15:13

    The warning looks like you are sending header information to the browser twice. Be sure to send the header information once to the browser for the same page. It would help if post.php and pluggable.php were posted here also so we could show you where this is happening. Regardless, you should be seeing the push notifications in your app from what I am seeing...

    点赞 评论