UNUserNotificationCenter's requestAuthorization returns success:false error:nil

930 Views Asked by At

I'm developing a swift app on my jailbroken iPhone 6s running iOS13.3, using theos on linux. I have some simple swift UI code to present a buttont to request local notification permissions:

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)")
      }
    }
  }
}

This always prints success:false error:nil, without anything popping up on the screen. If I print the current notification settings for the app using UNUserNotificationCenter.current().getNotificationSettings(), I get

<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>

(I formatted the above section so it's not a single long line)

My main questions are:

  1. Why is the requestAuthorization failing?
  2. Why is everything set to NotSupported in the settings above?

If it makes a difference, here is my 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>
1

There are 1 best solutions below

0
Enrico Borba On

I think this has to do with this being considered a system application, but I'm not sure. Either way, I was able to solve this by adding

<key>SBAppUsesLocalNotifications</key> <true/>

to the app's Info.plist.