UPDATE: I have just encountered this issue on an actual iPhone 5 running iOS 7. Will provide more information soon.
I think I have found a bug in the iOS 7 Simulator where a NSAttributedString does not appear. It would be great if someone else could test this to confirm it is a bug, then I will file a bug with Apple.
The problem appears to be the combination of using NSUnderlineStyleAttributeName and NSParagraphStyleAttributeName for NSAttributedString.
Here are the steps to reproduce:
1) In Xcode 5 create a new 'Single View Application'. Call it whatever.
2) In ViewController.m, replace the viewDidLoad method with:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;
NSAttributedString* attrStr = [[NSAttributedString alloc] initWithString:#"Lorem ipsum dolor sit" attributes:
#{NSUnderlineStyleAttributeName:#1,
NSParagraphStyleAttributeName:paragraph}];
UILabel* myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 0, 0)];
myLabel.backgroundColor = [UIColor greenColor];
myLabel.attributedText = attrStr;
[myLabel sizeToFit];
[self.view addSubview:myLabel];
}
3) Run on an iOS 7 device and then run it again in the iOS 7 simulator.
4) Lastly, set the deployment target to iOS 6 and run it on the iOS 6 simulator.
The results should be the following
iOS 7 Device: Displays correctly
iOS 7 Simulator: Only displays label background
iOS 6 Simulator: Displays correctly
Screenshots:
iOS7 Device
iOS7 Simulator
It appears this is not a Simulator bug, but an iOS 7 bug as I have been able to reproduce it on a device now. I have created a new question for it here: iOS 7 BUG - NSAttributedString does not appear
The bug appears to be the combination of using NSUnderlineStyleAttributeName & NSParagraphStyleAttributeName as attributes for a NSAttributedString.
Following line causing the issue.
NSParagraphStyleAttributeName:paragraph
This Worked for me
//Swift
let underlineAttribute = [NSUnderlineStyleAttributeName:NSNumber(int: 1)];
lblMessage.attributedText = NSAttributedString(string: "Your text", attributes: underlineAttribute)
//Am33t
Related
While presenting RPSystemBroadcastPickerView on iOS 13, it shows an exception with the following description: Fatal Exception: NSInvalidArgumentException
Application tried to present UIModalTransitionStylePartialCurl to or from non-fullscreen view controller .
I am using Xcode Version 11.3.1 (11C504). Is there any solution to stop this exception?
This is because iOS 13 uses a new presentation style instead of the full screen. And it doesn't support the PartialCurl transition you need to change the default presentation style:
var navigationController = new UINavigationController(ctrl);
navigationController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
ctrl.ModalTransitionStyle = UIModalTransitionStyle.PartialCurl;
PresentViewController(navigationController, animated: true, null);
Broken suddenly in iOS 10 simulators.
Prepare with:
[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
Implement:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
And the -motionBegan is never called.
Ok, so it turns out that they have changed how this works, and my "Prepare" above is now insufficient in iOS 10. You don't need to set that.
Now you must implement the motionBegan in the first responder that will receive the event, if it is your VC you need to implement:
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
I have troubles determining when the user taps on a user push notification on iOS 10.
So far, I have been using the -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] which is called when
Case 1: the application is active and the push is received
Case 2: when the user launched the app after taping a received notification
This method comments explicitly say
Note that this behavior is in contrast to application:didReceiveRemoteNotification:, which is not called in those cases, and which will not be invoked if this method is implemented.
All this work as expected.
Now iOS 10 deprecated this delegate method and introduced the UserNotification framework which I cannot use because I'm still targeting iOS 8 and 9.
When my app is running on iOS 10 and a push is received while the app is active (Case 1), the -[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] is called correctly.
Again on iOS 10, when the user starts the app by tapping a notification (Case 2) this method is not called.
I realise that when I implement the older -[UIApplicationDelegate application:didReceiveRemoteNotification:] it is the one that gets called in the Case 2
On iOS 8 and 9, in the Case 2 it is the -[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] method is called.
Does it mean that I have to update my application and implement the older delegate just for iOS 10?
So the question is, what is the proper implementation of handling the user interaction of a received push on iOS 10 without using the UserNotification framework.
cheers,
Jan
Swift code for iOS 10:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.currentNotificationCenter()
center.delegate = self
}
// ...
return true
}
#available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
print(response.notification.request.content.userInfo)
}
#available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
print(notification.request.content.userInfo)
}
We were facing the same problem here and we were only able to solve this problem on iOS 10 GM release by using the code on the answer given here: https://forums.developer.apple.com/thread/54332
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
if (version.majorVersion == 10 && version.minorVersion == 0) {
[self application: application
didReceiveRemoteNotification: userInfo
fetchCompletionHandler: ^(UIBackgroundFetchResult result) {
}];
}
With this fix our code started working again both on iOS 9 and 10.
We also had to change the way we handle application state behavior (UIApplicationStateActive, UIApplicationStateInactive and UIApplicationStateBackground) on push notifications, as it seems it also changed on iOS 10
EDIT:
It seems that application state behavior is back to normal on latest iOS 10 versions.
This has been fixed in iOS 10.1 Beta 1 !!
The -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] is correctly called when the user taps on a notification.
I just upgraded to Xcode V5.0 (5A1413) the build success but running the program against the emulator causes the error at the property definition:
#property (nonatomic, strong) CBCentralManager *manager; --> Thread 1:EXC_BAD_ACCESS (code=2, address=0x8)
I ran into the same issue and finally resorted to this:
UIDevice *currentDevice = [UIDevice currentDevice];
if ([currentDevice.model rangeOfString:#"Simulator"].location == NSNotFound) {
self.centralMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
On the Simulator, if I don't guard against creation of the CBCentralManager, I see centralManagerDidUpdateState: called with a CBCentralManager* that matches my strong property. It can be referenced and the state is CBCentralManagerStateUnsupported. That makes sense, but if I nil my strong manager property at that point (since I'm not going to be doing any BLE on a simulator that doesn't support it) I get the EXC_BAD_ACCESS. So, in the absence of a better answer, I suggest you simply guard against firing up the manager at all, as in my code above.
After updating to iOS 6.1, I'm getting this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:
Capturing 'operation' strongly in this block is likely to lead to a
retain cycle
Based on this answer, I can fix a retain cycle in ARC by using __weak variables. It is also says
Block will be retained by the captured object
Does anyone know how to solve this?
Thanks.
We are fortunate that XCode 4.6 is showing a warning to avoid this problem
It can be solved by providing a weak reference
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
**__weak AFImageRequestOperation *tempRequestOperation = requestOperation;**
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
UIImage *image = responseObject;
if (imageProcessingBlock) {
dispatch_async(image_request_operation_processing_queue(), ^(void) {
UIImage *processedImage = imageProcessingBlock(image);
dispatch_async(**tempRequestOperation**.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
success(operation.request, operation.response, processedImage);
});
});
} else {
success(operation.request, operation.response, image);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation.request, operation.response, error);
}
}];
OK here was the problem. I was keep downloading the Master branch from GitHub and now that I tried downloading AFNetworking from here (version 1.1.0) it doesn't show me the warning anymore.
I don't why the latest commits were not included in the master branch when I downloaded but clearly they've solved these strong refs in blocks warnings while ago.
Always check the website to see the latest released version or sync the latest commit from GitHub :) (It wasn't showing anything in my iOS 6.0 apps but Xcode 4.6 just brought them up)