问题描述
我正在运行 iOS13.3 的越狱 iPhone 6s 上开发一个 swift 应用程序,在 linux 上使用 theos。我有一些简单的 swift UI 代码来显示一个按钮来请求本地通知权限:
import SwiftUI
import UserNotifications
struct MainView: View {
var body: some View {
Button("Request Permission") {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) { success,error in
NSLog("success:\(success) error:\(error)")
}
}
}
}
这总是打印 success:false error:nil
,屏幕上不会弹出任何内容。如果我使用 UNUserNotificationCenter.current().getNotificationSettings()
打印应用程序的当前通知设置,我会得到
<UNNotificationSettings: 0x2824a8a80;
authorizationStatus: NotDetermined
notificationCenterSetting: NotSupported
soundSetting: NotSupported
badgeSetting: NotSupported
lockScreenSetting: NotSupported
carPlaySetting: NotSupported
announcementSetting: NotSupported
criticalAlertSetting: NotSupported
alertSetting: NotSupported
alertStyle: None
groupingSetting: Default
providesAppNotificationSettings: No>
(我格式化了上面的部分,所以它不是一个长行)
我的主要问题是:
- 为什么
requestAuthorization
失败? - 为什么在上面的设置中一切都设置为
NotSupported
?
如果它有所作为,这是我的 info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>cync</string>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>AppIcon29x29</string>
<string>AppIcon40x40</string>
<string>AppIcon57x57</string>
<string>AppIcon60x60</string>
</array>
<key>UIPrerenderedIcon</key>
<true/>
</dict>
</dict>
<key>CFBundleIcons~ipad</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>AppIcon29x29</string>
<string>AppIcon40x40</string>
<string>AppIcon57x57</string>
<string>AppIcon60x60</string>
<string>AppIcon50x50</string>
<string>AppIcon72x72</string>
<string>AppIcon76x76</string>
</array>
<key>UIPrerenderedIcon</key>
<true/>
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>com.enricozb.cync</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedplatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundLeversion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIrequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
解决方法
我认为这与将其视为系统应用程序有关,但我不确定。无论哪种方式,我都可以通过添加
来解决这个问题<key>SBAppUsesLocalNotifications</key> <true/>
到应用程序的 Info.plist
。