iOS使用__func__标识符打印方法名

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"%s",__func__);
    return YES;
}

打印结果

-[AppDelegate application:didFinishLaunchingWithOptions:]

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 10及以上版本中,可以使用`UNUserNotificationCenterDelegate`协议的`userNotificationCenter(_:didReceive:withCompletionHandler:)`方法来接收到新通知。如果您想要在接收到新通知时删除以前发送的通知,可以使用`UNUserNotificationCenter`类提供的`removeDeliveredNotifications(withIdentifiers:)`方法。 具体实现如下: 1. 在您的`AppDelegate`类中,将`UNUserNotificationCenterDelegate`设置为应用的通知中心的代理: ``` class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let center = UNUserNotificationCenter.current() center.delegate = self // ... return true } } ``` 2. 实现`UNUserNotificationCenterDelegate`协议的`userNotificationCenter(_:didReceive:withCompletionHandler:)`方法: ``` func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let notificationIdentifier = response.notification.request.identifier let center = UNUserNotificationCenter.current() center.removeDeliveredNotifications(withIdentifiers: [notificationIdentifier]) completionHandler() } ``` 在这个方法中,获取到`response`参数中通知的唯一标识符,并使用`UNUserNotificationCenter`类的`removeDeliveredNotifications(withIdentifiers:)`方法来删除以前发送的通知。最后,一定要调用`completionHandler()`方法来告诉系统已经处理完通知了。 注意:这个方法只会在用户点击通知时被调用,如果用户直接在通知中心中清除了通知,这个方法并不会被调用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值