手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:苹果相关

苹果推送注意事项

关于苹果的推送服务,网上的相关资料非常多,最简单的就是组合成一个数组,类似:

XML/HTML代码
  1. $arr['aps'] = array(  
  2.     'badge'=>1,  
  3.     'sound'=>'',  
  4.     'alert'=>'xxx'      
  5. );  

然后用json_encode处理一下之后,用ssl的方式发送给苹果:

XML/HTML代码
  1. chr(0) . pack("n", 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n", strlen($payload)) . $payload;  

$devideToken是设备的token,$payload就是上述的数组json_encode之后的数据。
测试的话是发给:ssl://gateway.sandbox.push.apple.com:2195,正式的话,将sandbox去掉即OK

于是这代码就好写了:

PHP代码
  1. /** 
  2.  * ApnsService.php 
  3.  * 
  4.  * @category 
  5.  * @package 
  6.  * @author   gouki <gouki.xiao@gmail.com> 
  7.  * @version 1.0 
  8.  * @created 2011-10-12-23:45 
  9.  */  
  10. class ApnsService {  
  11.     public $token;  
  12.     public $message;  
  13.     public $badge = 1;  
  14.     public $sound;  
  15.     public $ispad;  
  16.     public function __construct($token$message$badge = null, $sound = null, $ispad = 0) {  
  17.         $this->token = $token;  
  18.         $this->message = $message;  
  19.         $this->badge = $badge;  
  20.         $this->sound = $sound;  
  21.         $this->ispad = (int)$ispad;  
  22.     }  
  23.     public function send() {  
  24.         return $this->sendPushInfo();  
  25.     }  
  26.     public function sandboxSend() {  
  27.         return $this->sendPushInfo(true);  
  28.     }  
  29.     private function getPayload() {  
  30.         $body = array();  
  31.         if ($this->badge) {  
  32.             $body['aps']['badge'] = $this->badge;  
  33.         }  
  34.         if ($this->sound) {  
  35.             $body['aps']['sound'] = $this->sound;  
  36.         }  
  37.         $body['aps']['alert'] = $this->message;  
  38.         return $body;  
  39.     }  
  40.     private function getCertFile() {  
  41.         return Yii::getPathOfAlias("application") . ($this->ispad ? "/hdDis.pem" : "/iphoneDis.pem");  
  42.     }  
  43.     private function getSandboxCertFile() {  
  44.         return Yii::getPathOfAlias("application") . ($this->ispad ? "/hdDev.pem" : "/iphoneDev.pem");  
  45.     }  
  46.     private function getApplePushUrl($isSandbox = false) {  
  47.         return ($isSandbox == true ? "ssl://gateway.push.apple.com:2195" : "ssl://gateway.sandbox.push.apple.com:2195");  
  48.     }  
  49.     private function sendPushInfo($isSandbox = false) {  
  50.         $ctx = stream_context_create();  
  51.         stream_context_set_option($ctx'ssl''local_cert',  
  52.                                     ($isSandbox == true  
  53.                                             ? $this->getSandboxCertFile()  
  54.                                             : $this->getCertFile())  
  55.         );  
  56.         //stream_context_set_option($ctx, 'ssl', 'passphrase', '123456'); //如果设置了密码,这里就不能注释了  
  57.         $fp = stream_socket_client($this->getApplePushUrl($isSandbox), $err$errstr, 60, STREAM_CLIENT_CONNECT, $ctx);  
  58.         if (!$fp) {  
  59.             print "Failed to connect $err $errstr\n";  
  60.             return false;  
  61.         } else {  
  62.             //print "Connection OK\n";  
  63.         }  
  64.         $payload = json_encode($this->getPayload());  
  65.         //echo strlen($payload); //这里可以精心测试,最大不能超过256个字节即strlen超过256后苹果直接不予处理。  
  66.         $msg = chr(0) . pack("n", 32) . pack('H*'str_replace(' '''$this->token)) . pack("n"strlen($payload)) . $payload;  
  67.         fwrite($fp$msg);  
  68.         fclose($fp);  
  69.         return true;  
  70.     }  
  71. }  

上面的代码非常简单只是作了一个简单的处理和封装。不过有部分路径是基于yii的,所以要改一下就OK了。
主要是自己的记录。

Tags: 推送, badge, json

抄袭是对是错?

说起抄袭,让我想 起以前黄夏留教授的笑话系列中的一个:黄教授在监考,后期黄教授感慨,这次考试所见,全班同学几乎都在抄,不是你抄我就是我抄你,只有一个同学没抄,他的名字叫杨伟。

OK,再来说说互联网,互联网在国内抄的最成功的企业应该算是腾讯,把ICQ抄成了QQ,现在ICQ撑不下去了,但是QQ却越发红火;国内抄的最成功的项目应该算是新浪微博吧,不过也是占了一个小便宜,因为饭否被咔嚓了,机遇啊。
细算国内的一些项目,难道不都是在抄?有土豆和有土逼;微博和推特;开心、人人和非死不可;磨菇街和pintrest;等等等等

看到apple4.me上面的一段话:http://apple4.us/2012/04/why-we-should-be-sensitive-on-knockoff-software-products.html

  • 抄袭和模仿是必经阶段。
  • 太阳底下无新事,没有什么东西是完全原创的。
  • 中国互联网公司都抄,但不是每家都能抄成功。抄不等于成功,我们不应该单纯因为一家公司抄袭就反对它。
  • 美国也有抄袭。

好吧,其实每个人都在想,抄袭是成功的最简单的方法,毕竟抄袭之后,你已经不需要再考虑用户的需求,不是吗?你想着既然别人都成功了,证明他们确实是有这种需求的,所以在此基础上,又可以省下产品经理,省下创意人员,只需要设计人员就OK了。

-------
其实传统企业难道就没有抄袭了吗?也不见得。三株?总清楚的吧,脑黄金,也是吧;不过传统企业的抄袭不象互联网那样见效快。不知道以后会怎么样。。。

-------
不多谈了,交互设计师、创意,难道真的就是我们国家所缺的吗?交互的人这两天是越来越多了,大企业都在慢慢的重视这一块,只是,创意却还没有明显进步,哎:当然,我也没有什么创意,发牢骚总不犯法。

MAC复制文件后所增加的._开头的文件

当从mac复制文件到其他系统的时候,你会发现,目录下面多了一堆._开头的同名文件,很让人纠结,找了资料,说这是【 “Apple Double” 的文件系統處理機制】,虽然可以被删除,但很麻烦。

找到的原文是这么说的:

XML/HTML代码
  1. Before Mac OS X, the Mac OS used ‘forked’ files, which have two components: a data fork and a resource fork. The Mac OS Standard (HFS) and Mac OS Extended (HFS Plus) disk formats support forked files. When you move these types of files to other disk formats, the resource fork can be lost.  
  2.   
  3. With Mac OS X, there is a mechanism called “Apple Double” that allows the system to work with disk formats that do not have a forked file feature, such as remote NFS, SMB, WebDAV directories, or local UFS volumes. Apple Double does this by converting the file into two separate files. The first new file keeps the original name and contains the data fork of the original file. The second new file has the name of the original file prefixed by a “._ ” and contains the resource fork of the original file. If you see both files, the ._ file can be safely ignored. Sometimes when deleting a file, the ._ component will not be deleted. If this occurs you can safely delete the ._ file.   

好吧,我当然是没辙的,所以就只能用fin . -name "._*"|xargs rm这样的方式来删除了。这也是参考文章中的办法:

不过还是有一点小问题,那就是如果文件夹中有空格,其实在查询的时候是会被加上“\”的,也就导致在删除 的时候这个反斜杠变成了转义符。所以,这个目录还是先mv一下,改个名吧

Tags: mac, copy

IOS不再允许使用UDID

上面一则新闻来自macx,原文地址是:http://www.macx.cn/thread-2041511-1-1.html
iOS设备的设备唯一识别码UDID(unique device identifier),顾名思义就是每个设备只有这一个标识符,与设备硬件相关,是无法更改的。根据报道苹果从本周开始已经开始禁止第三方应用程序使用 iOS设备的UDID,并指出苹果将在下周开始加强设备UDID的隐私保护。

在iOS 5条款中,苹果已经对开发者进行了提醒,使用用户设备UDID是不赞成的并将逐步取缔这一做法。消息称苹果的十个App审核团队中已经有两个开始禁止使用UDID的应用通过审核了,据说下周将增加到四个。

一些第三方开发者表示,如果苹果有明确禁止使用UDID的条款颁布,那他们会按照新标准执行,不过他们还希望看看未来的形式如何发展。无论是开发者还是广告商都将受到新政策的严重影响。

苹果最近被隐私问题腿上风口浪尖,美国国会也几次三番要求苹果解释隐私保护问题,苹果可能也是出于外接压力才进一步紧缩iOS条款的。

如何查看自己iOS设备的UDID:
将设备链接到电脑iTunes,本机信息原来显示序列号的地方点击一下,即可看到标示符UDID信息
----------------
基于上述新闻,于是就有了下面这篇文章,嗯,当然也不是我写的,原文地址是:http://pingguohe.net/2011/08/25/uuid_after_ios5/

iOS5已经发布了6个beta版,除了在用户体验上的提升,对于开发者来说也有很多变化,最大的莫过于对UDID的限制访问。在之前的iOS应用 中,我们一般使用UDID来标记一个用户,基于UUID建立用户数据库。现在,安装了iOS5 beta 6的设备上已经取不到UDID,[UIDevice uniqueIdentifier] 只能返回一个“5.0”了。

取代被禁用的iOS UDID,其实有很多方法,比如,有人建议使用网卡mac,但我不建议使用这种方法,mac地址属于用户隐私数据,我想如果你试图获取用户mac并上传,review通不过。

官方给出的建议是CFUUID:

An alphanumeric string unique to each device based on various hardware details. (read-only) (Deprecated in iOS 5.0. Instead, create a unique identifier specific to your app.)

@property (nonatomic, readonly, retain) NSString *uniqueIdentifier
Special Considerations

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

通过CFUUIDCreate创建一个CFUUID对象,存入NSUserDefaults,作为用户身份的唯一标示。

官方对CFUUID对象的解释如下:

CFUUID objects are used by plug-ins to uniquely identify types, interfaces, and factories. When creating a new type, host developers must generate UUIDs to identify the type as well as its interfaces and factories.

UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over both space and time by combining a value unique to the computer on which it was generated—usually the Ethernet hardware address—and a value representing the number of 100-nanosecond intervals since October 15, 1582 at 00:00:00.

The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067. The hex representation looks, as you might expect, like a list of numerical values preceded by 0x. For example, 0xD7, 0x36, 0x95, 0x0A, 0x4D, 0x6E, 0x12, 0x26, 0x80, 0x3A, 0x00, 0x50, 0xE4, 0xC0, 0x00, 0x67 . To use a UUID, you simply create it and then copy the resulting strings into your header and C language source files. Because a UUID is expressed simply as an array of bytes, there are no endianness considerations for different platforms.

可以看到CFUUID就是对GUID的一种封装,提供了创建方法和各种各种格式转换的方法。

以下代码是我对CFUUID和NSUserDefaults的封装,可以作为唯一标识来使用。

C++代码
  1. //  
  2. //  NewUUID.h  
  3. //  
  4. //  Created by jiajun.gao jiajun.gao on 8/25/11.  
  5. //   
  6. //  Create a UUID by self.  
  7. //  
  8. //  Call like this:  
  9. //  
  10. //    String *iNeedUUID = [NewUUID identifier];  
  11. //  
  12.    
  13. #define NEW_UUID_KEY    @"uuid_created_by_developer"  
  14.    
  15. @interface NewUUID : NSObject {  
  16.    
  17.     NSString *uuid;  
  18.    
  19. }  
  20.    
  21. + (NSString *)identifier;  
  22.    
  23. @property (nonatomic, retain) NSString *uuid;  
  24.    
  25. @end  

NewUUID.m

C++代码
  1. #import <Foundation/Foundation.h>  
  2.    
  3. #import "NewUUID.h"  
  4.    
  5. @implementation NewUUID  
  6.    
  7. @synthesize uuid;  
  8.    
  9. - (id)init {  
  10.     self = [super init];  
  11.     if (self) {  
  12.         uuid = NULL;  
  13.         return self;  
  14.     }  
  15.    
  16.     return nil;  
  17. }  
  18.    
  19. + (id)_instance {  
  20.     static id obj = nil;  
  21.     if( nil == obj ) {  
  22.         obj = [[self alloc] init];  
  23.     }  
  24.    
  25.     return obj;  
  26. }  
  27.    
  28. + (NSString *)identifier {  
  29.    
  30.     NSUserDefaults *handler = [NSUserDefaults standardUserDefaults];  
  31.     [[NewUUID _instance] setUuid:[NSString stringWithFormat:@"%@", [handler objectForKey:NEW_UUID_KEY]]];  
  32.    
  33.     if (NULL == [[NewUUID _instance] uuid] || 46 > [[[NewUUID _instance] uuid] length]) {  
  34.    
  35.         CFUUIDRef uuid = CFUUIDCreate(NULL);  
  36.         CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);  
  37.    
  38.         NSString *result = [NSString stringWithFormat:@"%@-%@", @"new-uuid-", uuidStr];  
  39.    
  40.         CFRelease(uuidStr);  
  41.         CFRelease(uuid);  
  42.    
  43.         [[NewUUID _instance] setUuid:result];  
  44.    
  45.    
  46.         [handler setObject:[[NewUUID _instance] uuid] forKey:NEW_UUID_KEY];  
  47.         [handler synchronize];  
  48.     }  
  49.    
  50.     return [[NewUUID _instance] uuid];  
  51. }  
  52.    
  53. @end  

 

 

 

Tags: ios, udid

知识点: RAD Studio XE2新特性概览:多平台支持、原生iOS与Android、HD与3D动画及云

本文只是一个知识点,主要是Vampire和我说delphi可以开发原生IOS应用了,所以我觉得很奇怪就找了找资料,随手就把这篇infoQ的文章贴了出来。当然我的delphi是一塌糊涂,不过bobby和mpeg就不一样了,他们曾经靠这吃过饭 ,所以他们开发IOS就方便了。
嗯 ,原文在这里:http://www.infoq.com/cn/news/2011/09/RAD-Studio-XE2

继去年8月30日发布XE产品线到现在已经过去一年多的时间了,Embarcadero正准备发布其新版本的RAD Studio XE2工 具,其中包含了Delphi XE2、C++Builder XE2、RADPHP XE2及Prism XE2。此次发布带有很多新特性,最引入关注的莫过于对跨平台开发、Windows 64位、Amazon Cloud API、Native Android与iOS及HD与3D动画的支持了。

长久以来,众多Windows开发者都在使用Delphi与C++Builder针对微软平台创建应用,但现在他们也将目光瞄向了Mac OS X。其IDE并不能运行在Mac上,但编译器所生成的库则可以通过网络安装并运行在Mac计算机上,这样同一套源文件就会有两个应用库了。Delphi支 持Windows 64位,包含一个调试器和部署管理器。

Delphi与C++Builder还带有FireMonkey,这是一个新的平台,用于针对Windows、Mac OS X与iOS创建HD与3D动画。这些原生应用利用CPU与GPU来绘制动画,并且可以通过LiveBindings与任意数据类型进行连接。

Delphi与C++Builder应用可以部署到Amazon EC2与Windows Azure上,同时支持Amazon Simple Storage Service API、Queue Service与SimpleDB。

RADPHP现在则瞄准了iOS与Android设备,能以可视化的形式展现出应用在各个移动设备上的样子。开发人员还可以从PHP生成针对这些平台的原生应用。RADPHP使用了jQuery Mobile控件来设计界面。

除了对原有特性的增强外,Delphi Prism还增加了不少新特性,如下所示:

  • 全新的Oxygene Compiler 5.0
  • 编辑器可以显示出错误的详细信息、范围以及说明
  • 代码编辑器可以即时显示出编译错误
  • 针对选定的新错误的修复支持
  • 语言软接口与鸭子类型
  • 匿名接口实现
  • 增强的Oxidizer集成

资源:感兴趣的读者可以在这里查看RAD Studio XE2中更加完整的增强列表。

查看英文原文:New in RAD Studio XE2: Multiplatform, Native iOS&amp;Android, HD&amp;3D Animation, and Cloud

--------
对于XE最早的了解还是来自于delphi4php可惜那个项目实在让人失望,不知道这次这个怎么样

Tags: macosx, delphi, ios, android