K.K*_*K.K 20 ios springboard uialertcontroller
当我的iOS应用程序在后台时(我正在使用位置),我想显示警报视图.
例如,即使在以下情况下,优步合作伙伴(驱动程序)应用程序也会显示警报并播放声音:
我知道本地通知方法,如果用户关闭/更改设置中的通知,它不起作用.我正在寻找不同的东西.
当然,即使用户在"设置"中禁用"通知" ,应用程序也可以使用API 轻触静默远程通知didReceiveRemoteNotification: fetchCompletionHandler:.但是,警报是如何弹出的,这就是我想要找到的.
JAL*_*JAL 10
我认为优步有一些特殊权限或使用一些私有API,允许他们在不使用本地通知的情况下实现此行为.虽然我不知道优步如何在他们的合作伙伴应用程序中实现这一点,但我可以谈谈警报如何在主屏幕上工作.
SpringBoard是管理SpringBoard应用程序(SpringBoard.app)的单例类,它是iPhone的应用程序启动器.SpringBoard不使用标准UIAlertView/ UIAlertController类,因为它们不参与SpringBoard范围的警报系统.iOS 5引入SBAlertItem了用于在SpringBoard上显示UIAlertViews(电池通知警报,模拟解锁警报等).Apple使用SBAlertItem他们的锁定和主屏幕警报,我将假设Uber正在使用SBAlertItem这个答案.
SBAlertItem有一个受保护的伊娃UIAlertView *_alertSheet.假设这是正常的UIAlertView,您应该能够更改此警报的属性以满足您的需求.我还会阅读saurik的Cydia Substrate项目,特别是MobileSafety.mm来查看一些用例.我还发现了noweibogoodsleep,它提供了SBAlertItem在SpringBoard 上使用的一个例子.
我也发现SBUserNotificationAlert了一个子类SBAlertItem.这似乎有更多的方法来促进警报定制,可以比标准更好地满足您的需求SBAlertItem.
我意识到挂钩私有API可能不是你在问这个问题时所期望的.由于我不知道Uber是如何工作的,我只能根据我使用运行时和越狱设备的个人经验提供答案.
在对二进制文件进行一些静态分析之后,很明显他们没有使用PKPushRegistry(VOIP),未记录的NSNotificationCenter调用或SBAlertItem.
花了一点时间才找到它,但实际上它们正在使用CFUserNotification进行警报.该类文件的Mac,但私人的iOS.
我通过这样做找到了用法:
nm -u ~/Downloads/Payload/UberDriver.app/UberDriver | grep CFUserNotification
输出是:
_CFUserNotificationCancel
_CFUserNotificationCreate
_CFUserNotificationCreateRunLoopSource
_kCFUserNotificationAlertHeaderKey
_kCFUserNotificationAlertMessageKey
_kCFUserNotificationAlertTopMostKey
_kCFUserNotificationAlternateButtonTitleKey
_kCFUserNotificationDefaultButtonTitleKey
_kCFUserNotificationSoundURLKey
如果我grep for PKPushRegistry或SBAlertItem,两者都不返回任何结果.
可以通过将此文件导入项目来使用该类.
UPDATE
我有'工作'代码,但它立即调用回调函数(responseFlags设置为kCFUserNotificationCancelResponse)而不显示警报..
我使用相同的键和调用作为优步应用程序(比较下面列出的代码),所以必须有额外的东西.会继续寻找.
#import "CFUserNotification.h"
@interface AppDelegate ()
@property (nonatomic) CFRunLoopSourceRef runLoopSource;
@property (nonatomic) CFUserNotificationRef notification;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    SInt32 error;
    NSDictionary *keys = @{(__bridge NSString*)kCFUserNotificationAlertHeaderKey: @"Hello",
                           (__bridge NSString*)kCFUserNotificationAlertMessageKey: @"World",
                           (__bridge NSString*)kCFUserNotificationAlertTopMostKey: @YES,
                           (__bridge NSString*)kCFUserNotificationDefaultButtonTitleKey: @"asdf",
                           (__bridge NSString*)kCFUserNotificationAlternateButtonTitleKey: @"asdf",
                           };
    self.notification = CFUserNotificationCreate(NULL, 10, kCFUserNotificationPlainAlertLevel, &error, (__bridge CFDictionaryRef)keys);
    self.runLoopSource = CFUserNotificationCreateRunLoopSource(NULL, self.notification, NotificationCallback, 0);
    CFRunLoopAddSource(CFRunLoopGetMain(), self.runLoopSource, kCFRunLoopCommonModes);
    return YES;
}
void NotificationCallback(CFUserNotificationRef userNotification, CFOptionFlags responseFlags) {
    NSLog(@"got response: %lu", responseFlags);
}
您的问题错过了有关“优步合作伙伴”应用程序的最重要部分,这将使事情变得更加清晰。“优步合作伙伴”应用程序是企业应用程序,不限于 Appstore 指南。
它没有像其他建议的答案那样获得任何特殊权限。
SBAlertItem无论声音\通知设置如何,都可以显示警报视图,但如果您的最终目标是进入应用商店,不幸的是,您的应用将因使用私有 API 而被拒绝。
| 归档时间: | 
 | 
| 查看次数: | 3634 次 | 
| 最近记录: |