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

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?