簡體   English   中英

更新到IOS 8和Xcode 6后,本地通知無法正常工作

[英]Local Notification not working since updating to IOS 8 and Xcode 6

自更新到IOS 8和Xcode 6后,是否有其他人遇到本地通知問題? 我的應用程序運行正常,並且notification.firdate是從日期選擇器設置並且工作正常, notification.alertBody顯示正常。 現在我已經更新它不起作用。 我添加了斷點,我的被激活的值存儲在其中。 誰能幫幫我嗎?

您需要更新代碼才能在iOS8中接收通知。 更多信息在這里

Objective-C代碼:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    // Override point for customization after application launch.
    return YES;
}

SWIFT代碼:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//registering for sending user various kinds of notifications
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert |UIUserNotificationType.Badge, categories: nil)   
// Override point for customization after application launch.     
return true
}

要接收本地NSNotification,請按照以下步驟操作:

  1. didFinishLaunchingWithOptions方法中將代碼添加到appDelegate.h

     if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM