3 Replies
      Latest reply: Nov 2, 2016 4:54 AM by eskimo RSS
      joelwmale Level 1 Level 1 (0 points)

        Hi all,

         

        I've just started coding Swift, looking to get into some app development - I've got a local application which I'm wanting to test some notifications in (just all in-house, so code inside the app generating it).

         

        A few hours ago I deployed a version to my iPhone that had a "first" set up of it, and it worked OK. Now whenever I run to the iPhone (just connecting through Xcode) it says:

         

        Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}


        I understand not being able to do this, if I were distributing the app or something - but the fact that it doesn't work on the simulator for xcode, and it also now isn't working for me when I deploy from xcode to my iPhone? Is this on purpose?

         

        I'm really not ready to commit $149AUD to the developer program - it's quite a huge investment, but I'd really like to at least be able to test some core aspects all locally...

         

        Again - I understand some features (e.g push notifications), but local ones all through the app? I must be doing something wrong for that to be blocked.

        • Re: Testing local in-app notifications without developer account?
          eskimo Apple Staff Apple Staff (6,675 points)

          How are you posting the notifications?  UIApplication?  Or the new User Notifications framework?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Testing local in-app notifications without developer account?
              joelwmale Level 1 Level 1 (0 points)

              My code looks like:

              
              /
                  let content = UNMutableNotificationContent()
                  content.title =  title
                  content.body = body
                 
                  /
                  /
                 
                  let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: interval, repeats: false)
                  let request = UNNotificationRequest.init(identifier: "vultrManager", content: content, trigger: trigger)
                 
                  /
                  let center = UNUserNotificationCenter.current()
                  center.add(request) { (error) in
                      if error != nil {
                          sent = false
                      }
                  }
              

               

              I believe it's using the UserNotifications framework.

                • Re: Testing local in-app notifications without developer account?
                  eskimo Apple Staff Apple Staff (6,675 points)

                  I believe it's using the UserNotifications framework.

                  Indeed.  I tested this in my office, using:

                  • a ‘clean’ developer account that was created via the public web site and has never been a member of a paid developer programme

                  • a newly created test app with the code shown below (basically your code with a few tweaks)

                  It ran on my device without any problems, and was able to display notifications.

                  The one thing I did not do was enable any special entitlements.  In fact, given that I’m using my unpaid developer account the Capabilities tab in Xcode doesn’t even list Push Notifications as an option anymore, and I get a nice note at the bottom saying:


                  9 Capabilities Unavailable

                  Learn More About Advanced App Capabilities >>>


                  I’m not sure why your app is tripping over an aps-environment entitlement check.  I recommend you create a new test app to see if the issue is tied to your app or your Xcode setup.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                  import UIKit
                  import UserNotifications
                  
                  class MainViewController : UITableViewController {
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (granted, error) in
                              NSLog("granted: \(granted)")
                              if let error = error {
                                  NSLog("error: \(error)")
                              }
                          })
                      }
                  
                      func test() {
                          let content = UNMutableNotificationContent() 
                          content.title = "NoteTest2"
                          content.body = "Body \(Date())"
                  
                          let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false) 
                          let request = UNNotificationRequest(identifier: "vultrManager", content: content, trigger: trigger) 
                  
                          let center = UNUserNotificationCenter.current() 
                          center.add(request) { (error) in 
                              if let error = error { 
                                  NSLog("error: \(error)")
                              } else {
                                  NSLog("added")
                              } 
                          } 
                      }
                  
                      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                          NSLog("tableView(_:didSelectRowAt:)")
                          self.test()
                          self.tableView.deselectRow(at: indexPath, animated: true)
                      }
                  }