Not getting APNS Device token on ios 13 - apple-push-notifications

I have issue related to APNS device token . Before I was using Xcode 10.2 and iOS 12.1. At this moment I used to get the device token in delegate method
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
I am registering for APNS like this and it was working fine.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
Now when installed iOS 13 to my iPhone device and using Xcode 11 , the delegate method didRegisterForRemoteNotificationsWithDeviceToken is not called. Unable to understand this problem .
I have already done research over this , I know there are some changes in getting token from the delegate method but in my case delegate method is not even called. Again it's working fine for iOS 12.

Just reboot your iPhone. It's as simple as that and in 90% of cases it will solve your problem.

Logon on https://appleid.apple.com/, then open url "https://developer.apple.com/account/ios/identifier/bundle"
or "https://developer.apple.com/account/resources/certificates/list".
First, Create two New Certificates:
(1)Apple Development
Sign development versions of your iOS, macOS, tvOS, and watchOS apps. For use in Xcode 11 or later.
(2)Apple Distribution
Sign your apps for submission to the App Store or for Ad Hoc distribution. For use with Xcode 11 or later.
Then find menu "Identifiers" via url "https://developer.apple.com/account/resources/identifiers/list".
Edit your Identifiers of your app, make sure that Development SSL Certificate & Production SSL Certificate is added to the Push Notifications.
Next, open menu "Profiles" via url "https://developer.apple.com/account/resources/profiles/list".
Make sure that the Certificates as type of DistributionFor which will be used in Xcode 11 or late, and save
Lastly, download the Provisioning Profile file and the CA Certificates files created to your MAC, which will be added to XCode and key-chain application by double click the files separately.
What's more, remember to reboot your cell phone, and make sure that you had setup the remote notification correctly.

I also faced the same problem. I tried many scenarios. I got success after doing the below steps:
Restarted device
Called the registerForRemoteNotifications
method in the main thread.
In my case, I was getting a device token, but there is a delay in response (I think due to registering remote notifications in a background thread). But after moving [[UIApplication sharedApplication] registerForRemoteNotifications] in the main thread, all works fine.
Here is my code:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = delegate;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
[self callCompletion:TRUE completion:completion];
});
}
}];
Hope this will help.

I just solved this problem this way following below steps.
Add some print in didRegisterForRemoteNotificationsWithDeviceToken method and keep devices connected.
Went to the target capabilities.
Turn the Push Notification Off
Build & Run the app on device and wait.
Then check the console you got Fail push notification error message.
Stop running the app.
Turn the Push Notification On again.
Goto https://developer.apple.com/ Choose Account -> Certificates, Identifiers & Select your project ProvisionalProfiles -> Keys ->click on edit and save after that download provisonal profile and double click on it.
Build & Run the app on device.
Then its working fine.
I hope this help someone.

It is related to DeviceSupport missing in your XCode installation, for platform version used by your deploy device.
In my case, the 13.1 platform were missing.
To solve, just add the DeviceSupports in folder
Xcode.app/Contents/Develper/Platforms/iPhoneOS.platform/DeviceSupport
You can download missing DeviceSupport from:
https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport

Try this.
Remove your application.
Reboot your phone.
Build and Run(reinstall your application) on your device.
It worked for me.

Related

App not showing same result as Xcode simulator

I am new to Xcode and app programming and developed a small app to get certain calendar events and present them in a NSTableview.
The program is working fine in my Xcode simulator.
However when I build for running and start the App on my iMac, is is not returning any calendar events. Just runs and ends without any errors.
What am I missing here?
Problem was solved by adding [store requestAccessToEntityType:(EKEntityTypeEvent) completion:^(BOOL granted, NSError *error) after the allocation of the EKEventStore.

MKMapView not Rendering in iOS 8 or later

I'm having an issue in MKMapView in iOS 8.x.x. Application works fine iOS 7.x.x but not in iOS 8.x.x. On device it shows only annotations but no map behind.
I tried to forcefully Reset my Device as well but no luck.
I added these 2 Values in info.plist as well as it was a requirement for iOS 8 and onwards
<key>NSLocationAlwaysUsageDescription</key>
<string>Location is required to find out where you are</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is required to find out where you are</string>
and added this lines of code in my Viewdidload.
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
//[self.locationManager requestAlwaysAuthorization];
self.myMapView.showsUserLocation = YES;
}
By adding these 2 values in info.plist and the above lines of code, I'm able to get the User's Location and annotation in showing on map for user's location but Map is Blank.
Similar to this post:
MKMapView showing blank screen in iOS 8
Had the very same thing on IOS8.3 both sim and device.
Solved by running the system Maps App (it displayed empty grid as well) for a minute till it downloaded maps. After that my MKMapView started rendering as normal.
try add the delegate methods: - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
and check the solution for you error message.
also check this solution i don't got rid of the grind but at least i got rid of the didFail error.
but seems to be an issue of iOS8 because on iOS8.3 works fine the same code.

How can I make a Rate-Button in iOS7?

I want to add a rate-button to my application. How can I do this?
- (IBAction)rateGame {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"itms-apps://itunes.apple.com/app/idYOUR_APP_ID"]];
}
In the simulator, this doesn't work. (Can't test it on a real device right now)
Is this the correct way to do this or should I try something else?
Your code is correct for launching the App Store with the app page open; I use the same code in my shipping app. This is the best you can achieve on iOS 7. It doesn't work on the iOS Simulator because the simulator doesn't have the App Store or iTunes apps installed, so there's nothing to launch.
Try using iRate. Handle all network connection and other related issues. And easy to implement. Just drag and drop files to your AppDelegate. It automatically configures all the required terms(like app store id, etc) from the info.plist files, and gets all the required information from app store.
NOTE: iRate can be used without any configuration, just by dragging and adding the files to project. See this example.
#import "iRate.h"
#implementation AppDelegate
+ (void)initialize
{
//configure iRate
[iRate sharedInstance].previewMode = YES;// yes for testing
}

Out of the blue I can't get security scoped bookmarks

Blimey, this Sandboxing makes me despair: I have an app that's been released on Apple's store (so, in theory, it's gone through review...), it's a slide show player - nothing too fancy - the user can drag and drop images onto an NSTableView or select through NSOpenPanel. Anyway, I thought I'd use it myself so I recompiled a copy onto my laptop and all of a sudden I'm not allowed security bookmarking:
QuickSlide(1412) deny mach-lookup com.apple.scopedbookmarksagent.xpc
The above appears whenever I drag and drop images or select them through the NSOpenPanel.
I have the following entitlements:
The code I'm using to generate the bookmarks is:
-(NSData*)genSec:(NSURL*)aURL
{
NSError *error;
NSData *secData = [aURL bookmarkDataWithOptions:(NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess | NSURLBookmarkCreationPreferFileIDResolution)
includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
if (error) {
[self setReport: [NSString stringWithFormat:#"Can't access %# due to SandBoxing",aURL]];
return nil;
}
return secData;
}
Sure enough, the report method is also fired along with the Console logging.
It's never done this before in the months I did of development. I've also tried it on my dev Mac Pro crate, tried code-signing with different or no signing, and even downloaded it from the App Store (tried twice with 2 different accounts); all with the same result. I've also used the very handy Receigen app to check the entitlements in the compiled bundle. I'm running 10.7.5. The only thing that stops it from throwing errors is if I un-check the 'enable sandboxing' option in Xcode and compile.
Argghhh. Can someone point out the blindingly obvious mistake that somehow has slipped through 2 beta-testers, me, and an App Store reviewer...?!!!!
It has to be something obvious doesn't it?
UPDATE: I got a colleague to download a fresh copy to his laptop and there was no problem with sandboxing. I'd still appreciate it if anyone can shed some light on what's happening to my installs...
Todd.
Sure enough it seems from your entitlements that it is something obivous. You need to add this one as well:
com.apple.security.files.bookmarks.app-scope
I don't know why it was working before and now isn't, but I'm positive you need to declare this entitlement for security scoped bookmarks to work.

UIAlertView with text fields not moving up

I want to display a prompt to get a user's username and password.
I am doing this by displaying a UIAlertView and adding UITextFields as subviews to it.
Recently I moved my project over to XCode 4.2 and I updated all my project settings. My base SDK is set to iOS 5.0 and my deployment target is set to 4.0.
I then noticed that it was only being built for armv7 architectures and so I changed that to include armv6 as well since I would like to support the iPhone 3G as well.
After doing this I noticed that the UIAlertView wasn't moving up as before and now it was being covered by the keyboard when it was displayed. I read in the Apple documentation that you shouldn't subclass UIAlertViews (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html) and so I changed the way I was doing things. This didn't solve the problem.
I have noticed that I can get it to work on my phone (an iPhone 4, so armv7 architecture) by setting the Build Setting - "Build active architecture only" to YES.
I suspect that the problem is something to do with trying to build for armv6 (and indeed removing this from the architectures I am trying to build for gives me alerts which move up correctly).
I suppose I should get to my question now... I'm struggling to understand why this is behaving the way it is. I read somewhere (can't find the link now) that you don't need to move the alert up manually when adding a text field to a UIAlertView in iOS 4 and above. Since I am building for at least iOS 4 shouldn't this work on both architectures?
Also, how can I get it to build for armv6 and still have alerts which move up correctly?
Edit: Maybe I was wrong but I have noticed that I have 2 instances of my phone which I can deploy the app to. Selecting the first one and building gives me an app where the UIAlertViews don't move up when they should, but selecting the second one makes it work properly. Would post a screenshot, but I'm a new user and so I don't have the permissions necessary yet...
Oki,
I've managed to come up with a solution which works and gets the UIAlertView to be in the correct position, but I'm still not entirely sure what the root cause of the problem is.
I solved it by responding to the UIAlertViewDelegate method willPresentAlertView: and doing the following
- (void) willPresentAlertView: (UIAlertView *) alertView {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
if (keyWindow.center.y - alertView.center.y < 0.001f) {
CGPoint center = [alertView center];
center.y = center.y - 108.0f;
[alertView setCenter:center];
}
}
It checks whether the UIAlertView is in the center of the screen and moves it up if it is (i.e. if the OS hasn't already calculated the correct position of it). Note: You would need to add a check for which specific orientation the device is in and then adjust the amount the alert is moved up accordingly if you wanted this to work for both portrait and landscape orientations.

Resources