dragon456101 2014-05-20 01:37
浏览 92
已采纳

如何在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)];
    if(launchOptions!=nil){
        NSString *msg = [NSString stringWithFormat:@"%@", launchOptions];
        NSLog(@"%@",msg);
        [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];
    NSLog(@"%@",msg);
    [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];
}

@end

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 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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题