当前位置:  编程技术>移动开发
本页文章导读:
    ▪XMPP通信开发-服务器好友获取以及监听状态变化        XMPP通讯开发-服务器好友获取以及监听状态变化在 XMPP通讯开发-好友获取界面设计   我们设计了放QQ的列表功能,这里我们获取我们服务器上的 数据。 这一部分知识我们可以查看smack_3_3_0/s.........
    ▪ 苹果通报推送服务(APNS)一些关键特性摘要        苹果通知推送服务(APNS)一些关键特性摘要 前段时间,仔细研究了APNS的文档,把一些关键的地方记录了下来,弄懂这些对于理解APNS的规则,至关重要。   1. If APNs attempts to deliver a notification bu.........
    ▪ 使用signApk签名ROM包出现addDigestsToManifest异常的解决       使用signApk签名ROM包出现addDigestsToManifest错误的解决错误信息类似下面 java.lang.NullPointerException at com.android.sigjava.lang.NullPointerException at com.android.signapk.SignApk.addDigestsToManifest(SignApk.java:179) at com.and.........

[1]XMPP通信开发-服务器好友获取以及监听状态变化
    来源: 互联网  发布时间: 2014-02-18
XMPP通讯开发-服务器好友获取以及监听状态变化

在 XMPP通讯开发-好友获取界面设计   我们设计了放QQ的列表功能,这里我们获取我们服务器上的 数据。

这一部分知识我们可以查看smack_3_3_0/smack_3_3_0/documentation/roster.html,这个是官方的文档,介绍了我们可以使用Roster来获取,同时我们还可以注册监听器,当用户的状态信息发生变化的时候可以通知UI进行更新。

获取好友实体

Roster是一个集合,我们看一下集合中的实体是由什么组成的。

Every user in a roster is represented by a RosterEntry, which consists of:

  • An XMPP address (e.g.jsmith@example.com).
  • A name you've assigned to the user (e.g. "Joe").
  • The list of groups in the roster that the entry belongs to. If the roster entry belongs to no groups, it's called an "unfiled entry".

简单的说就是XMPP地址,用户名,用户组

 public void getRoster(){
        if(conn != null){
            roster = conn.getRoster();
            Collection<RosterEntry> entries = roster.getEntries();
            for(RosterEntry entry : entries){
                System.out.println(entry);
            }
        }
   }

我调试的打印信息如下,可以看到格式里面分别包含用户名,XMPP地址,用户组

dfffff: dfff@zhangjie [Friends]
sdfsdf: sdf@zhangjie [Friends]
123: 123@zhangjie [Friends]

获取好友的分组

代码如下:

  Collection<RosterGroup> groups = roster.getGroups();
           for(RosterGroup group : groups){
               System.out.println(group.getName());
           }

终端的调试信息:

客户
好友
Friends

当然我们还可以添加用户组和用户同时也可以删除

createGroup

createEntry

removeEntry

监听好友状态变化

Roster还能够监听状态变化,方法如下:

/**
     * 注册监听状态变化
     */
    public void getRosterPresenceChange(){
        if(roster != null){
            roster.addRosterListener(new RosterListener(){
                @Override
                public void entriesAdded(Collection<String> addresses) {
                    
                }

                @Override
                public void entriesUpdated(Collection<String> addresses) {
                    
                }

                @Override
                public void entriesDeleted(Collection<String> addresses) {
                    
                }

                @Override
                public void presenceChanged(Presence prsnc) {
                    System.out.println("Change: "+ prsnc.getFrom()+" status :"+prsnc.getStatus());
                }
                
            });
        }
    }


将好友中的123登出:

Change: 123@zhangjie/Spark 2.6.3 status :null

然后登陆123:

Change: 123@zhangjie/Spark 2.6.3 status :在线

下一章会将界面和后台数据结合起来,实现用户列表功能


源码项目:https://github.com/jwzhangjie/IChat_PC.git


    
[2] 苹果通报推送服务(APNS)一些关键特性摘要
    来源: 互联网  发布时间: 2014-02-18
苹果通知推送服务(APNS)一些关键特性摘要

前段时间,仔细研究了APNS的文档,把一些关键的地方记录了下来,弄懂这些对于理解APNS的规则,至关重要。

 

1. If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available.

假如用户手机不在线,可能没有信号或者关机吧,APNs会存储转发,等用户在线时再发送

 

2.Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications.

如果用户不在线,通知会合并,只会保留最新的一条。假如你给用户发了两条通知,但用户反馈说,只收到了一条,那么很可能是用户当时不在线,APNs的合并策略生效,只保留了最近一条

 

3.If the device remains offline for a long time, any notifications that were being stored for it are discarded

 

4.The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.

这个很重要,payload,就是最后生成的那段Json,不得超过256字节。如果超过了,建议去掉一些不需要的参数,把alert,就是提示信息的字数减少

 

5.don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack.

6.If you send a notification that is accepted by APNs, nothing is returned.

发送成功的木有返回,只有发送失败的才会返回

 

7.If you send a notification that is malformed or otherwise unintelligible, APNs returns an error-response packet and closes the connection. Any notifications that you sent after the malformed notification using the same connection are discarded, and must be resent.

这条非常重要,如果有error-response,那么这条之后的通知都需要重发。有很多开源的库,在发苹果通知时都没有检测error-response,如果你不小心用了,那么用户很可能反馈“怎么没有通知啊”

 

8.The notification identifier in the error response indicates the last notification that was successfully sent(实际情况不是,实际上返回的是出错的那条通知的ID). Any notifications you sent after it have been discarded and must be resent.When you receive this status code, stop using this connection and open a new connection.

这是对上一条的补充,如果出错了,需要关闭当前的连接,并且重新连接再发。error-response中返回的通知ID,可以帮助我们找出哪条出错了,这样就能知道哪些需要重发了

 

9.When a push notification cannot be delivered because the intended app does not exist on the device, the feedback service adds that device’s token to its list.

APNS的feedback service会返回那些已经卸载的设备的token--device_token。存储这些token,下次就不用再给他们发了,可以节省点资源。需要注意的是:feedback的接口读取一次,APNS就会清空它的列表,下次再读取时,返回的就是这两次读取之间这段时间新产生的device_token。

 

只有把这些搞清楚,才方便我们理解苹果推送的规则,知道自己推送上的一些不足之处。搞懂这些规则后,我自己封装了个Java的类库,已经开源并放到Github上了,下一篇文章奉上详情。

1 楼 liangcoder 2013-09-11  
研究的很仔细

    
[3] 使用signApk签名ROM包出现addDigestsToManifest异常的解决
    来源: 互联网  发布时间: 2014-02-18
使用signApk签名ROM包出现addDigestsToManifest错误的解决
错误信息类似下面
java.lang.NullPointerException
at com.android.sigjava.lang.NullPointerException
at com.android.signapk.SignApk.addDigestsToManifest(SignApk.java:179)
at com.android.signapk.SignApk.main(SignApk.java:325)napk.SignApk.addDigestsToManifest (
SignApk. java :179)
at com.android.signapk.SignApk.main(SignApk.java:325)
这个问题来源于压缩包在复制移动时可能在包里产生一个和压缩包同名的0KB文件
删掉即可


删掉 这个  

本文出自 “清源教育” 博客,转载请注明此处,谢谢!欢迎登录清源教育官网,查看更多视频教程。

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3