PushKit和传统长连接方式的比较
2016-05-23 21:31
323 查看
iOS and PushKit
This post will cover basic concepts for VoIP apps on iOS.
I will not post any code (Google it out if necessary). I will compare two ways of developing VoIP on iOS and write down my notes while developing them.
VoIP apps before iOS 8
Before iOS 8, VoIP apps had to maintain persistent background connection (VoIP socket) with the server. When a new incoming call arrived iOS gave some execution time to the app so it could notify user (via local notifications).
Developers could add remote push notifications to inform users about incoming calls but apps did not receive any execution time there. Remote push notifications are not reliable since users can disable them at anytime.
To be available as much as possible apps had to perform the following steps:
1.) Configure one of the app’s sockets for VoIP usage
2.) Before moving to the background set a keepAlive timeout handler to be executed periodically
3.) Observing network changes
When keepAlive timeout expired (minimum 10 min) or when network configuration changed, app received a few sec (< 10) of execution time to maintain VoIP socket with the server.
This way of working had two major down sides. It was a drain on the battery and if the app was closed by the user (or crashed) all VoIP calls would have been missed, until the app was executed by the user.
VoIP apps with PushKit (iOS 8+)
With iOS 8 there is a new, more energy efficient way to create iOS VoIP apps - VoIP Push notifications.
VoIP notifications have higher priority compared to regular push notifications and they give you some execution time when received.
They are more reliable (more about this in notes :)) and a lot more useful. Received VoIP push notification will wake up or launch your app (almost) anytime, regardless if your app crashed, was terminated by user, or device was restarted.
You no longer have to maintain persistent connections with your server, set timeouts or observe network changes.
Your VoIP app must do two things on startup:
1.) Initialize PushKit (VoIP type) and set its delegate. User does not need to allow it and cannot disable it
2.) Register for posting user notifications about incoming calls (user confirmation is required)
There is no need for any active connection to the server when there is no active call. When incoming call is created, server will send VoIP push notification to your device.
This notification will wake your app and give you some time to connect to the server (if needed) and notify user about the call. When a call ends you can disconnect from the server.
Battery drain is minimal since your app doesn’t need to run in the background. User can kill your app and still be reachable.
Sample code with PushKit integration can be found in here.
My notes regarding PushKit
Not receiving notifications after device reboot:
- Before initializing PushKit start a background task. Finish this task when PushKit token is received.
Not receiving pushes after app crashed:
- This happens only if your app crashes while processing push notifications. Make sure you do not have a bug in your PushKit delegate function.
Not receiving pushes after app is few hours in background:
- This is a bug in iOS and it it occurs after few days, sometimes after few hours. When your app gets to this point, it has to be launched manually. We have reported this bug to Apple. If you are facing same issue, you can follow this thread on Apple Dev forum: https://devforums.apple.com/message/1113824
Written by: Miha Majcen
特别感谢本文原作者的分享:http://blog.biokoda.com/post/114315188985/ios-and-pushkit
相关文章推荐
- Windows下的包管理器Chocolatey
- 父子控制器
- 求一个数的所有因子
- 事务四大特征:原子性,一致性,隔离性和持久性(ACID)
- 《Spring学习笔记》:Spring、Hibernate、struts2的整合前奏
- gitlab新仓库的创建
- 日志管理
- [drp 6]接口和抽象类的区别,及其应用场景
- [drp 6]接口和抽象类的区别,及其应用场景
- linux 下面安装oracle
- block
- C++作业6
- arm-linux-gcc交叉编译工具链安装
- Hibernate分页查询的实现
- PHP环境配置
- leetcode 347.Top K Frequent Elements
- 人脸识别算法准确率最终超过了人类 The Face Recognition Algorithm That Finally Outperforms Humans
- Activity生命周期和启动模式
- 逻辑思维题 微信18954274246 答案
- 取数组中最大值和最小值