iPhone Push消息全攻略.1
要做一个iPhone Push消息的需求,从简单test的开始。
1、先添加一个app ID
.jpg)
.jpg)
这篇文章说只能保留一个。
device token,即设备令牌,不是系统唯一标识(见获取iOS设备的基本信息),需要在应用启动时发起到apple服务器请求,注册自己的设备和应用,并获得这个device token。
@property
(
strong
,
nonatomic
)
UIViewController
*viewController;
//
// com_sencloud_testAppDelegate.m
// test
//
// Created by chen minglei on 13-7-11.
// Copyright (c) 2013
年
chen minglei. All rights reserved.
//
#import
"com_sencloud_testAppDelegate.h"
@implementation
com_sencloud_testAppDelegate
@synthesize
window;
@synthesize
viewController;
- (
void
)applicationDidFinishLaunching:(
UIApplication
*)application {
[
window
addSubview:viewController.view];
[windowmakeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplicationsharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSStringstringWithFormat: @"Error: %@", err];
NSLog(str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
}
@end
.jpg)
2013-07-11 21:18:36.139 test[6386:907] Registering for push notifications...
2013-07-11 21:19:05.988 test[6386:907] Device Token=<c8cd88d5 9c0d7407 fc697357 3d3778e5 5e83b92e d40c7588 a595be18 119c6f92>
import javapns.back.PushNotificationManager;
import javapns.back.SSLConnectionHelper;
import javapns.data.Device;
import javapns.data.PayLoad; public class ApnsAct {
public static void main(String[] args) throws Exception {
try {
String deviceToken = "c8cd88d59c0d7407fc6973573d3778e55e83b92ed40c7588a595be18119c6f92"; PayLoad payLoad = new PayLoad();
payLoad.addAlert("Test");
payLoad.addBadge(4);
payLoad.addSound("default"); PushNotificationManager pushManager = PushNotificationManager
.getInstance();
pushManager.addDevice("iPhone", deviceToken); // Connect to APNs
String host = "gateway.sandbox.push.apple.com";
int port = 2195;
String certificatePath = "/Users/plan9x/Desktop/test.p12";
String certificatePassword = "test";
pushManager.initializeConnection(host, port, certificatePath,
certificatePassword,
SSLConnectionHelper.KEYSTORE_TYPE_PKCS12); // Send Push
Device client = pushManager.getDevice("iPhone");
pushManager.sendNotification(client, payLoad);
pushManager.stopConnection(); pushManager.removeDevice("iPhone");
} catch (Exception e) {
e.printStackTrace();
}
}
}
java.io.IOException
: failed to decrypt safe contents entry:
java.lang.ArithmeticException
: / by zero
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1277)
at java.security.KeyStore.load(KeyStore.java:1183)
at javapns.back.SSLConnectionHelper.<init>(Unknown Source)
at javapns.back.PushNotificationManager.initializeConnection(Unknown Source)
ApnsAct.java:27
)
Problem with empty or null password in 'APNS.newService().withCert(certificate.p12, password)'
When a password was not defined on keyStore generation I have the following situations:
1 - Using a null password in APNS.newService().withCert(certificate.p12, password) returns a "NullPointerException";
2 - Using an empty password in APNS.newService().withCert(certificate.p12, password) returns "java.io.IOException: failed to decrypt safe contents entry: java.lang.ArithmeticException: / by zero"
reported as bug 6415637, and affects any Java library basically.
withCert
throw an
IllegalArgumentException
instead.
英文版
iPhone Push消息全攻略.1的更多相关文章
- VSCode插件开发全攻略(七)WebView
更多文章请戳VSCode插件开发全攻略系列目录导航. 什么是Webview 大家都知道,整个VSCode编辑器就是一张大的网页,其实,我们还可以在Visual Studio Code中创建完全自定义的 ...
- Android使用XML全攻略(1)
Android使用XML全攻略(1) Android 是针对移动设备的一种新兴的开源操作系统和 SDK.借助它,您可以创建功能强大的移动应用程序.当您的应用程序可以访问 Web 服务时,其吸引力 ...
- 开发小白也毫无压力的hexo静态博客建站全攻略 - 躺坑后亲诉心路历程
目录 基本原理 方法1 - 本机Windows下建站 (力荐) 下载安装node.js 用管理员权限打开命令行,安装hexo-cli和hexo 下载安装git 初始化hexo 使用hexo gener ...
- VSCode插件开发全攻略(八)代码片段、设置、自定义欢迎页
更多文章请戳VSCode插件开发全攻略系列目录导航. 代码片段 代码片段,也叫snippets,相信大家都不陌生,就是输入一个很简单的单词然后一回车带出来很多代码.平时大家也可以直接在vscode中创 ...
- VSCode插件开发全攻略(五)跳转到定义、自动补全、悬停提示
更多文章请戳VSCode插件开发全攻略系列目录导航. 跳转到定义 跳转到定义其实很简单,通过vscode.languages.registerDefinitionProvider注册一个provide ...
- VSCode插件开发全攻略(四)命令、菜单、快捷键
更多文章请戳VSCode插件开发全攻略系列目录导航. 命令 我们在前面HelloWord章节中已经提到了命令写法,这里再重温一下. context.subscriptions.push(vscode. ...
- VSCode插件开发全攻略(二)HelloWord
更多文章请戳VSCode插件开发全攻略系列目录导航. 写着前面 学习一门新的语言或者生态首先肯定是从HelloWord开始. 您可以直接克隆我放在GitHub上vscode-plugin-demo 的 ...
- 谈谈Vue.js——vue-resource全攻略
本篇文章主要介绍了谈谈Vue.js——vue-resource全攻略,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 概述 上一篇我们介绍了如何将$.ajax和Vue. ...
- 打造一个高逼格的android开源项目——小白全攻略 (转)
转自:打造一个高逼格的android开源项目 小引子 在平时的开发过程中,我们经常会查阅很多的资料,最常参考的是 github 的开源项目.通常在项目的主页面能看到项目的简介和基本使用,并且时不时能看 ...
随机推荐
- ti processor sdk linux am335x evm /bin/setup-targetfs-nfs.sh hacking
#!/bin/sh # # ti processor sdk linux am335x evm /bin/setup-targetfs-nfs.sh hacking # 说明: # 本文主要对TI的s ...
- UVA 11374 Airport Express 机场快线(单源最短路,dijkstra,变形)
题意: 给一幅图,要从s点要到e点,图中有两种无向边分别在两个集合中,第一个集合是可以无限次使用的,第二个集合中的边只能挑1条.问如何使距离最短?输出路径,用了第二个集合中的哪条边,最短距离. 思路: ...
- AngularJS promise()
实例说明一 <!DOCTYPE html> <html ng-app="my-app"> <head> <meta charset=&qu ...
- 【C#学习笔记】写文件
using System; using System.IO; namespace ConsoleApplication { class Program { static void Main(strin ...
- Java之UncaughtExceptionHandler
概述: UncaughtExceptionHandler是为了捕获没有被捕获的异常,包括运行时异常,执行错误(内存溢出等),子线程抛出的异常等,你可以在uncaughtException(xx)里对后 ...
- HDU 4539 郑厂长系列故事——排兵布阵
http://acm.hdu.edu.cn/showproblem.php?pid=4539 郑厂长系列故事——排兵布阵 Time Limit: 10000/5000 MS (Java/Others) ...
- ASIHTTPREQUEST 文档
http://blog.csdn.net/ysysbaobei/article/details/17026577 Please note that I am no longer working on ...
- Authentication with SignalR and OAuth Bearer Token
Authentication with SignalR and OAuth Bearer Token Authenticating connections to SignalR is not as e ...
- hadoop1.2.1 伪分布式配置
主要配置 core-site.xml hdfs-site.xml mapred-site.xml
- mybatis系列-07-输出映射
7.1 resultType 使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功. 如果查询出来的列名和pojo中的属性名全部不一致,没有创建 ...