相关疑难解决方法(0)

在ios10中添加本地通知 - swift 3

编辑:所以把应用程序放在后台就行了.

原版的:

所以我一直在尝试向新的UNUserNotificationCenter添加通知,但我似乎没有得到它.

我的视图控制器有一个动作:

@IBAction func sendPressed(_ sender: AnyObject) {
    let content = UNMutableNotificationContent()

    content.title = "Hello"
    content.body = "What up?"
    content.sound = UNNotificationSound.default()

    // Deliver the notification in five seconds.
    let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)

    // Schedule the notification.
    let center = UNUserNotificationCenter.current()
    center.add(request) { (error) in
        print(error)
    }
    print("should have been added")
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let center = UNUserNotificationCenter.current()
    center.requestAuthorization([.alert, .sound]) { …
Run Code Online (Sandbox Code Playgroud)

uilocalnotification swift swift3 ios10 unusernotificationcenter

27
推荐指数
2
解决办法
5万
查看次数

如何在iOS 10中安排本地通知(objective-c)

我想使用iOS 10安排本地通知.我想知道如何做到这一点.我已经浏览了网络,但我一直在寻找线索,只是为了注册和处理通知.不适用于本地通知的安排.

那么,有谁知道怎么做?

objective-c ios10 usernotifications

9
推荐指数
2
解决办法
2万
查看次数

多个UNUserNotifications未触发

我正在设置多个UNUsernotnotifications,如下所示,

- (void)viewDidLoad {
    [super viewDidLoad];
    notifCount = 0;
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              if (!error) {
                                  NSLog(@"request succeeded!");

                                  [self set10Notif];

                              }
                          }];
}
Run Code Online (Sandbox Code Playgroud)

在该set10Notif方法中,我设置多个(8个用于测试)通知,时间与当前时间相差10秒.

-(void) set10Notif
{
    notifCount = notifCount+1;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0") && notifCount < 10)
    {
        // create actions
      NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

      [calendar setTimeZone:[NSTimeZone localTimeZone]];

       NSDate *fireD = [[NSDate date] dateByAddingTimeInterval:notifCount*10];

       NSString *fireStr = [self returnStringFromDate:fireD withFormat:@"hh/mm/ss dd/MM/yyyy"];

       NSDateComponents *components …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios10 usernotifications unusernotificationcenter

4
推荐指数
1
解决办法
2254
查看次数