import Permissionable
class ViewController: UIViewController {
func askPermission() {
Permissions.Camera.request(self) { (success: Bool) -> Void in
if success {
print("\o/")
}
}
}
func askForPushPermission() {
Permissions.Push.request(self, categories) { (success: Bool) -> Void in
if success {
print("\o/")
}
}
}
}
//===================================================
import Permissionable
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
{...}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
Permissions.didFinishRegisteringForPushNotifications(error)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
//Do domething with the token
Permissions.didFinishRegisteringForPushNotifications(nil)
}
}
//===================================================
import Permissionable
class UserHandler {
func logout() {
Permissions.reset()
}
}
要运行示例项目,请克隆该仓库,并首先从示例目录中运行pod install
。
要将此库本地化,请确保在您的Localizable.strings文件中包含以下条目:
"Yes" = "<您的翻译>";
"No" = "<您的翻译>";
"Please" = "<您的翻译>"; //默认提示标题
"Would you mind if we send you push notifications?" = "<您的翻译>"; //推送通知的默认消息
"Would you mind if we access your camera?" = "<您的翻译>"; //设备摄像头的默认消息
"Would you mind if we access your photos?" = "<您的翻译>"; //用户照片的默认消息
"Uh oh" = "<您的翻译>"; //出错时的默认提示标题
"Looks like we can't access the camera... Would you like to go to the Settings app to check?" = "<您的翻译>"; //提示用户到设置应用检查权限的默认消息
"Looks like we can't access your photos... Would you like to go to the Settings app to check?" = "<您的翻译>"; //提示用户到设置应用检查权限的默认消息
iOS 8+
Permissionable可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中即可
pod "Permissionable"
请注意这将安装所有可能的权限(以及它们相关的库),这将增加您应用的依赖项。查看以下命令以找到一个适合您需求的命令
pod "Permissionable/Camera"
pod "Permissionable/Photos"
Bell App Lab,[email protected]
Permissionable基于MIT许可。有关更多信息,请参阅LICENSE文件。