java苹果沙盒验证参数问题_java 使用APNS 完成苹果推动 请教?

看下这一段,https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2,

An application must register with Apple Push Notification service for the operating systems on a device and on a computer to receive remote notifications sent by the application’s provider. Registration has three stages:

The app registers for remote notifications.

The system sets up remote notifications for the app and, if registration is successful, passes a device token to the app delegate.

The app sends its device token to the push provider.

The actions that take place during this sequence are illustrated by Figure 3-3 in “Token Generation and Dispersal.”

Device tokens can change. Your app needs to reregister every time it is launched—in iOS by calling the registerForRemoteNotificationTypes: method of UIApplication,

e3274d2b97be4bdc0aff1ba29e64ecd0.png

从官方的app的代码来看:

// Delegation methods

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

const void *devTokenBytes = [devToken bytes];

self.registered = YES;

[self sendProviderDeviceToken:devTokenBytes]; // custom method

}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

NSLog(@"Error in registration. Error: %@", err);

}

这两个都是在app启动的时候,如果app调用了以下的方法来注册push notification,那么,第一个delegate,返回成功的token,第二个delegate告诉app,注册失败,而成功之后,就是把token发送到你的服务器端,通常而言,你可以用这样的处理方法,一旦app启动,那么应该从服务器端禁止push notification,一旦app转移到background状态,就在服务器端启动push notification,这个在app里面都有处理的delegate,需要服务器编写代码实现这一点。

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值