0

の通知を登録するに提出通知を登録するには、エラーアプリのスローエラーの詳細は以下のとおりです。ここではスウィフト3では、アプリケーションは、ここでは、IOS 8.1

<EXPR>:3:1: error: expected member name or constructor call after type name 
Error 
^ 

<EXPR>:3:1: note: use '.self' to reference the type object 
Error 
^ 
.self 

は、iOS 10.1

で正常に実行されているコードであります
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) 
{ 
    print("Failed to register Notification Error = ", Error)   
} 

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 
{ 
    print("Device Token = ", Data) 
} 



func registerForRemoteNotification() 
{ 
    if #available(iOS 10.0, *) 
    { 

     let center = UNUserNotificationCenter.current() 
     center.delegate = self 
     center.requestAuthorization(options: [.sound, .alert, .badge]) 
     { (granted, error) in 
      if error == nil 
      { 
       UIApplication.shared.registerForRemoteNotifications() 


      } 
     } 
    } 
    else 
    { 
     if #available(iOS 8.0, *) 
     { 
      UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)) 
      UIApplication.shared.registerForRemoteNotifications() 

     } 
     else 
     { 
      UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert]) 
     } 
    } 
} 
@available(iOS 10.0, *) 
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) 
{ 

    if let dicAps = notification.request.content.userInfo["aps"] as? NSDictionary 
    { 
     AppUtilities.showAlertWithMessage(title: APP_TITLE as NSString, message: "\(dicAps.object(forKey: "msg")!)" as NSString) 
    } 
    completionHandler([.alert, .badge, .sound]) 
} 

//Called to let your app know which action was selected by the user for a given notification. 
@available(iOS 10.0, *) 
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) 
{ 
    print("User Info = ",response.notification.request.content.userInfo) 
} 

iOS 8から10.1で動作するアプリケーションを実装しようとしていますが、iOS 10.1.1のiPhone 5sではうまく動作します。しかし、私はiOS 8.1でシミュレータでアプリを実行すると、上記のエラーが常にスローされます。私が何かを見逃してしまった場合は、私を修正してください。

ありがとうございます。

+0

どのラインがエラーの原因ですか? – rmaddy

+0

@JK Patel:プッシュ通知がシミュレータで動作しない、https://stackoverflow.com/questions/21741259/push-notifications-in-mavericks-ios-simulator –

+0

@rmaddy私がdidFailToRegisterForRemoteNotificationsWithErrorからエラーを受け取るシミュレータ。 –

答えて

0

申し訳ありませんが、この機能をテストするにはハードウェアを見つける必要があります。

プッシュ通知はシミュレータでは利用できません。 iTunes Connectのプロビジョニングプロファイルが必要なため、デバイスにインストールする必要があります。つまり、アップルのiPhoneデベロッパープログラムに参加して99ドルを支払う必要があるかもしれません。

ソース:How can I test Apple Push Notification Service without an iPhone?

+0

このエラーについては、Appleの開発者向けドキュメントを参照しています。 –

関連する問題