Date   

Re: Trouble with NSTableViews in macOS 11.x

Sak Wathanasin
 



On 26 Mar 2021, at 22:46, Jon Gotow <gotow@...> wrote:

I ran into this when updating all of my apps for Big Sur. You'd think the "Full Width" style would make the table, well, full width, but it doesn't. I think the solution was to set the tableview style to "Plain". 

Both "plain" and "fullwidth" sort of work; my mistake was using IB to set this property and it had no effect. When I set it in code (thanks, Shane!), I could see differences in behaviour. Both styles result in the gridlines being drawn from edge to edge. However,

1) with "fullwidth"
- the table is still indented (6 or 16 px as before)
- if the enclosing scrollview has borders, gridlines are drawn for empty rows
- if the scrollview has no borders, gridlines are not drawn for empty rows

2) with "plain"
- the table is no longer indented
- gridlines are not drawn for empty rows whether the scrollview has borders or not

We want gridlines on empty rows, but our tables are also borderless as the designers wanted the border around the table name label as well. Bascially, we want the 10.15 behaviour back. That it behaves differently depending on whether the enclosing scrollview is bordered or not doesn't feel right.

I guess it's worth raising a bug report with Apple and seeing what comes of it.

Thanks to everyone
Sak


Re: Compiler error - method not found on object which conforms to protocol

Allan Odgaard <groups-io@...>
 

On 27 Mar 2021, at 2:41, Sandor Szatmari wrote:

[…] This is outlined in pseudocode below.

There is nothing conceptually wrong with what you sketch in your pseudo-code.

Please post an actual runnable example, as your pseudo-code has typos and lack context, something like the below compiles (and runs) just fine:

@protocol dataSrcProto
- (NSUInteger)serverPort;
@end

@interface MyDataSource : NSObject <dataSrcProto>
@end

@implementation MyDataSource
- (NSUInteger)serverPort { return 8000; }
@end

int main (int argc, char const* argv[])
{
    id <dataSrcProto> server; // obtained from seomewhere
    fprintf(stderr, "%ld\n", server.serverPort);
    return 0;
}


Re: Compiler error - method not found on object which conforms to protocol

Sandor Szatmari
 

Thanks Sak,

On Mar 27, 2021, at 04:54, Sak Wathanasin <sw@...> wrote:

On 27 Mar 2021, at 01:41, Sandor Szatmari <admin.szatmari.net@...> wrote:
@protocol dataSrcProto
-(NSUinteger)serverPort;
@end

serverPort isn't a property, so you have to use

This is how I’m working around the error right now.  Like this I get a compiler warning, method not found, return type defaults to id.  
[self.dataSource serverPort];


Port = (NSUInteger)[self.dataSource serverPort];

This succeeds at runtime, but of course smells, and doesn’t squelch the warning.

If you want it to be a property, make it so

I tried implementing serverPort as a property and I still get the same error

Thanks,
Sandor


@protocol dataSrcProto
@property (readonly) NSUinteger serverPort;
@end

Regards
Sak


Re: Compiler error - method not found on object which conforms to protocol

Sak Wathanasin
 



On 27 Mar 2021, at 01:41, Sandor Szatmari <admin.szatmari.net@...> wrote:
@protocol dataSrcProto
-(NSUinteger)serverPort;
@end

serverPort isn't a property, so you have to use

[self.dataSource serverPort];

If you want it to be a property, make it so

@protocol dataSrcProto
@property (readonly) NSUinteger serverPort;
@end

Regards
Sak


Compiler error - method not found on object which conforms to protocol

Sandor Szatmari
 

I have a server class which is abstracted to receive it’s final configuration from it’s data source. The idea is you instantiate the server set the data source and then start the server. During startup the server reads some configuration, such as the port to start on, from the data source. This is outlined in pseudocode below. This is mostly working except for a compiler error I can’t explain. The compiler issues an error about accessing the port from the data source.

Port = self.dataSource.serverPort;

It says “Property ‘-serverPort’ not found on object of type ‘id<dataSrcProto>’”

Anyone come across this?

——— server.h/m ———-
@class server
@property (readwrite,assign) id<dataSrcProto> dataSource
-(void)start
{
Port = self.dataSource.serverPort;
… start the server
}
@end

——— dataSource.h/m ———-
@class dataSource <dataSrcProto>
-(NSUinteger)serverPort{return 8080;}
@end

——— dataSrcProto.h ———-
@protocol dataSrcProto
-(NSUinteger)serverPort;
@end

Sandor


Re: Trouble with NSTableViews in macOS 11.x

Sak Wathanasin
 



On 26 Mar 2021, at 22:46, Jon Gotow <gotow@...> wrote:

I ran into this when updating all of my apps for Big Sur. You'd think the "Full Width" style would make the table, well, full width, but it doesn't. I think the solution was to set the tableview style to "Plain". 



I had set the style to "full-width" in IB, but that had no effect. Let me give "plain" a shot.

Thanks for the suggestions,

Sak


Re: Trouble with NSTableViews in macOS 11.x

Jon Gotow
 

I ran into this when updating all of my apps for Big Sur. You'd think the "Full Width" style would make the table, well, full width, but it doesn't. I think the solution was to set the tableview style to "Plain". 

 - Jon

On Fri, Mar 26, 2021 at 1:46 PM Sak Wathanasin <sw@...> wrote:
The tableviews in one of our apps is behaving strangely when running on macOS 11.x. I have managed to reproduce thsi with a simple test app. Essentially, the issue occurs if if I build using the 11.x SDK (ie using Xcode 12.2 or later) when running on 11.x.

What happens is that the table is shifted to the right when running on 11.x. This happens with both view-based and cell-based tables. For example, the frame for the (0,0) cell is

on 10.15: (1.0, 1.0, 116.0, 24.0)
on 11.2.3: (6.0, 1.0, 116.0, 24.0)

Even weirder, if I set the enclosing NSScrollView to "no borders" the frame is now

(16.0, 1.0, 116.0, 24.0)

AND the grid lines don't extend the full width of the table, AND the line after the last row isn't drawn (that's what got QA on to the case).

On 10.15, my test tables look like this - both tables the same except for the border, and both aligned left:

But on 11.x, it looks like this:

As you can see, the "no border" version is very different.

Looking at the release notes (https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-11), the only thing I could see that might be relevant is

NSScrollView
• When linked on macOS Big Sur 11 or later, an NSScrollViewwith automaticallyAdjustsContentInsets set to truewill continue to respect the safe-area insets of the window even when titlebarAppearsTransparent is set to true. For apps linked earlier than macOS Big Sur 11 NSScrollViewwill ignore the automatic insets when titlebarAppearsTransparent is set to true.

But my scrollviews have this turned off.

I haven't seen any reports of this issue so I assume I'm doing something very stupid. Any idea what? I can send the test project to anyone who has the time to look at it; it's tiny.

Many thanks for any help

Sak Wathanasin
Network Analysis Limited           http://www.network-analysis.ltd.uk


Re: Trouble with NSTableViews in macOS 11.x

Shane Stanley
 

On 27 Mar 2021, at 6:46 am, Sak Wathanasin <sw@network-analysis.ltd.uk> wrote:

What happens is that the table is shifted to the right when running on 11.x.
Try adding this to your code at an appropriate point:

if (@available(macOS 11.0, *)) {
myTableView.style = NSTableViewStyleFullWidth;
}


--
Shane Stanley <sstanley@myriad-com.com.au>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Trouble with NSTableViews in macOS 11.x

Sak Wathanasin
 

The tableviews in one of our apps is behaving strangely when running on macOS 11.x. I have managed to reproduce thsi with a simple test app. Essentially, the issue occurs if if I build using the 11.x SDK (ie using Xcode 12.2 or later) when running on 11.x.

What happens is that the table is shifted to the right when running on 11.x. This happens with both view-based and cell-based tables. For example, the frame for the (0,0) cell is

on 10.15: (1.0, 1.0, 116.0, 24.0)
on 11.2.3: (6.0, 1.0, 116.0, 24.0)

Even weirder, if I set the enclosing NSScrollView to "no borders" the frame is now

(16.0, 1.0, 116.0, 24.0)

AND the grid lines don't extend the full width of the table, AND the line after the last row isn't drawn (that's what got QA on to the case).

On 10.15, my test tables look like this - both tables the same except for the border, and both aligned left:

But on 11.x, it looks like this:

As you can see, the "no border" version is very different.

Looking at the release notes (https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-11), the only thing I could see that might be relevant is

NSScrollView
• When linked on macOS Big Sur 11 or later, an NSScrollViewwith automaticallyAdjustsContentInsets set to truewill continue to respect the safe-area insets of the window even when titlebarAppearsTransparent is set to true. For apps linked earlier than macOS Big Sur 11 NSScrollViewwill ignore the automatic insets when titlebarAppearsTransparent is set to true.

But my scrollviews have this turned off.

I haven't seen any reports of this issue so I assume I'm doing something very stupid. Any idea what? I can send the test project to anyone who has the time to look at it; it's tiny.

Many thanks for any help

Sak Wathanasin
Network Analysis Limited           http://www.network-analysis.ltd.uk


Re: Exception not being caught in try statement

Gary L. Wade
 

Try surrounding the call with beginEditing and endEditing on the text storage. If it still happens, submit a feedback to Apple with the full crash log.
--
Gary L. Wade
http://www.garywade.com/

On Mar 26, 2021, at 4:11 AM, Mark Allan via Cocoa-dev <cocoa-dev@lists.apple.com> wrote:

Hi folks,

Some users are reporting a crash that I can't reproduce, and in an attempt to gain additional diagnostics from a user, I wrapped the affected line in a try/catch block. For two users it resolve the crash, but for a third, it's still crashing at the same point!

The crash occurs when a user attempts to open the "About" window from my app's main menu item. I'm not using the standard about panel as there's a few additional items I need to display, one of which is an NSTextView which I populate with the contents of an RTF file from within the app bundle.

I've symbolicated the crash log to find it's happening when populating that TextView. The line in question now reads as follows:

@try {
[self.aboutBox.creditsTextView readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]];
} @catch (NSException *exception) {
NSLog(@"Error loading the contents of the text file for the About Box. %@", exception);
//Check we have a file at the expected path
if([[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]]){
NSLog(@"Yes. Found the RTF credits file");
// check the attributes in case somehow there's no permission to read the file
NSDictionary *fileAttributes =[[NSFileManager defaultManager] attributesOfItemAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"] error:nil];
NSLog(@"RTF file has following attributes %@", fileAttributes);
}
else {
NSLog(@"Nope, file not found");
}
}

This is the crash log from the newest build (with the try/catch around that line):

Performing @selector(showAboutBox:) from sender NSMenuItem 0x600000634540
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff206ea6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff204223c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2079ea9a -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x00007fff2079c953 -[__NSArrayM insertObject:atIndex:].cold.2 + 0
4 CoreFoundation 0x00007fff20610421 -[__NSArrayM insertObject:atIndex:] + 1135
5 UIFoundation 0x00007fff23c223ab __defaultTabStops_block_invoke + 161
6 libdispatch.dylib 0x00007fff203cd7c7 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff203ce96b _dispatch_once_callout + 20
8 UIFoundation 0x00007fff23c229d7 -[NSMutableParagraphStyle setTabStops:] + 199
9 UIFoundation 0x00007fff23c3c697 -[NSRTFReader defaultParagraphStyle] + 75
10 UIFoundation 0x00007fff23c3c5be -[NSRTFReader _mutableParagraphStyle] + 112
11 UIFoundation 0x00007fff23c36113 controlClass + 1757
12 UIFoundation 0x00007fff23c356b4 -[NSRTFReader attributedString] + 76
13 UIFoundation 0x00007fff23c311a6 _NSReadAttributedStringFromURLOrData + 3213
14 UIFoundation 0x00007fff23d46985 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithURL:options:documentAttributes:error:] + 228
15 AppKit 0x00007fff23677d9a -[NSTextView readRTFDFromFile:] + 126
16 MyAppHere 0x0000000105fa18a7 MyAppHere+ 227495
17 AppKit 0x00007fff230af7fd -[NSApplication(NSResponder) sendAction:to:from:] + 283
18 AppKit 0x00007fff231b2611 -[NSMenuItem _corePerformAction] + 413

Any ideas what's going on? Other than the file not being found, why else might the object at line 3 in the backtrace be nil...and more interestingly, why is the exception not being caught?

Thanks
Mark


Re: Exception not being caught in try statement

Jon Gotow
 

What's the architecture of the machine on which exceptions aren't being caught? Is the try block working on Intel and not on M1?

The crash is happening as the RTF reader is setting up the tab stops in the default paragraph format, so I'd assume there's something wonky about the tab stops or other paragraph formatting in your RTF doc.

- JOn

On Mar 26, 2021, at 5:11 AM, Mark Allan <markjallan@gmail.com> wrote:

Hi folks,

Some users are reporting a crash that I can't reproduce, and in an attempt to gain additional diagnostics from a user, I wrapped the affected line in a try/catch block. For two users it resolve the crash, but for a third, it's still crashing at the same point!

The crash occurs when a user attempts to open the "About" window from my app's main menu item. I'm not using the standard about panel as there's a few additional items I need to display, one of which is an NSTextView which I populate with the contents of an RTF file from within the app bundle.

I've symbolicated the crash log to find it's happening when populating that TextView. The line in question now reads as follows:

@try {
[self.aboutBox.creditsTextView readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]];
} @catch (NSException *exception) {
NSLog(@"Error loading the contents of the text file for the About Box. %@", exception);
//Check we have a file at the expected path
if([[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]]){
NSLog(@"Yes. Found the RTF credits file");
// check the attributes in case somehow there's no permission to read the file
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"] error:nil];
NSLog(@"RTF file has following attributes %@", fileAttributes);
}
else {
NSLog(@"Nope, file not found");
}
}

This is the crash log from the newest build (with the try/catch around that line):

Performing @selector(showAboutBox:) from sender NSMenuItem 0x600000634540
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff206ea6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff204223c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2079ea9a -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x00007fff2079c953 -[__NSArrayM insertObject:atIndex:].cold.2 + 0
4 CoreFoundation 0x00007fff20610421 -[__NSArrayM insertObject:atIndex:] + 1135
5 UIFoundation 0x00007fff23c223ab __defaultTabStops_block_invoke + 161
6 libdispatch.dylib 0x00007fff203cd7c7 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff203ce96b _dispatch_once_callout + 20
8 UIFoundation 0x00007fff23c229d7 -[NSMutableParagraphStyle setTabStops:] + 199
9 UIFoundation 0x00007fff23c3c697 -[NSRTFReader defaultParagraphStyle] + 75
10 UIFoundation 0x00007fff23c3c5be -[NSRTFReader _mutableParagraphStyle] + 112
11 UIFoundation 0x00007fff23c36113 controlClass + 1757
12 UIFoundation 0x00007fff23c356b4 -[NSRTFReader attributedString] + 76
13 UIFoundation 0x00007fff23c311a6 _NSReadAttributedStringFromURLOrData + 3213
14 UIFoundation 0x00007fff23d46985 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithURL:options:documentAttributes:error:] + 228
15 AppKit 0x00007fff23677d9a -[NSTextView readRTFDFromFile:] + 126
16 MyAppHere 0x0000000105fa18a7 MyAppHere+ 227495
17 AppKit 0x00007fff230af7fd -[NSApplication(NSResponder) sendAction:to:from:] + 283
18 AppKit 0x00007fff231b2611 -[NSMenuItem _corePerformAction] + 413

Any ideas what's going on? Other than the file not being found, why else might the object at line 3 in the backtrace be nil...and more interestingly, why is the exception not being caught?

Thanks
Mark




Exception not being caught in try statement

Mark Allan
 

Hi folks,

Some users are reporting a crash that I can't reproduce, and in an attempt to gain additional diagnostics from a user, I wrapped the affected line in a try/catch block. For two users it resolve the crash, but for a third, it's still crashing at the same point!

The crash occurs when a user attempts to open the "About" window from my app's main menu item. I'm not using the standard about panel as there's a few additional items I need to display, one of which is an NSTextView which I populate with the contents of an RTF file from within the app bundle.

I've symbolicated the crash log to find it's happening when populating that TextView. The line in question now reads as follows:

@try {
[self.aboutBox.creditsTextView readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]];
} @catch (NSException *exception) {
NSLog(@"Error loading the contents of the text file for the About Box. %@", exception);
//Check we have a file at the expected path
if([[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]]){
NSLog(@"Yes. Found the RTF credits file");
// check the attributes in case somehow there's no permission to read the file
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"] error:nil];
NSLog(@"RTF file has following attributes %@", fileAttributes);
}
else {
NSLog(@"Nope, file not found");
}
}

This is the crash log from the newest build (with the try/catch around that line):

Performing @selector(showAboutBox:) from sender NSMenuItem 0x600000634540
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff206ea6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff204223c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2079ea9a -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x00007fff2079c953 -[__NSArrayM insertObject:atIndex:].cold.2 + 0
4 CoreFoundation 0x00007fff20610421 -[__NSArrayM insertObject:atIndex:] + 1135
5 UIFoundation 0x00007fff23c223ab __defaultTabStops_block_invoke + 161
6 libdispatch.dylib 0x00007fff203cd7c7 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff203ce96b _dispatch_once_callout + 20
8 UIFoundation 0x00007fff23c229d7 -[NSMutableParagraphStyle setTabStops:] + 199
9 UIFoundation 0x00007fff23c3c697 -[NSRTFReader defaultParagraphStyle] + 75
10 UIFoundation 0x00007fff23c3c5be -[NSRTFReader _mutableParagraphStyle] + 112
11 UIFoundation 0x00007fff23c36113 controlClass + 1757
12 UIFoundation 0x00007fff23c356b4 -[NSRTFReader attributedString] + 76
13 UIFoundation 0x00007fff23c311a6 _NSReadAttributedStringFromURLOrData + 3213
14 UIFoundation 0x00007fff23d46985 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithURL:options:documentAttributes:error:] + 228
15 AppKit 0x00007fff23677d9a -[NSTextView readRTFDFromFile:] + 126
16 MyAppHere 0x0000000105fa18a7 MyAppHere+ 227495
17 AppKit 0x00007fff230af7fd -[NSApplication(NSResponder) sendAction:to:from:] + 283
18 AppKit 0x00007fff231b2611 -[NSMenuItem _corePerformAction] + 413

Any ideas what's going on? Other than the file not being found, why else might the object at line 3 in the backtrace be nil...and more interestingly, why is the exception not being caught?

Thanks
Mark


Re: Push Notification device token from APNS auth response.

Alex Zavatone
 

And from the WWDC 2020 10095 Notification video.

class APNSHelperSwiftNSObject
{
    @objc(stringFromDeviceToken:) public class func stringFromDeviceToken2(deviceToken: Data) -> String
    {
        let tokenComponents = deviceToken.map { data in String(format: "%02.2hhx", data) }
        let deviceTokenString = tokenComponents.joined()

        

        return deviceTokenString
    }
}


Cheers,
Alex Zavatone


On Mar 12, 2021, at 10:55 AM, Alex Zavatone via groups.io <zav@...> wrote:

Sometimes we want to get the string value of the device token after requesting push auth from APNS in didRegisterForRemoteNotificationWithDeviceToken.

Here’s how you can get that string value in Objective-C and Swift.

Cheers,
Alex Zavatone


//
//  APNSHelper.h
//  pushy
//
//  Created by Alex Zavatone on 3/10/21.
//  Copyright © 2021. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface APNSHelper : NSObject

+ (NSString *)stringFromDeviceToken:(NSData *)deviceToken;

@end

NS_ASSUME_NONNULL_END


//
//  APNSHelper.m
//  pushy
//
//  Created by Alex Zavatone on 3/10/21.
//  Copyright © 2021. All rights reserved.
//

#import "APNSHelper.h"

@implementation APNSHelper

+ (NSString *)stringFromDeviceToken:(NSData *)deviceToken
{
    NSUInteger length = deviceToken.length;
    if (length == 0) {
        return nil;
    }
    const unsigned char *buffer = deviceToken.bytes;
    NSMutableString *hexString  = [NSMutableString stringWithCapacity:(length * 2)];
    for (int charIndex = 0; charIndex < length; charIndex++) {
        [hexString appendFormat:@"%02x", buffer[charIndex]];
    }
    return [hexString copy];
}

@end




//
//  APNSHelperSwift.swift
//  pushy
//
//  Created by Alex Zavatone on 3/11/21.
//

import Foundation

@objc(APNSHelperSwift)
class APNSHelperSwift: NSObject
{
    
    @objc(stringFromDeviceToken:) public class func stringFromDeviceToken(deviceToken: Data?) -> String?
    {
        if (deviceToken == nil) {
            return nil;
        }
        
        let length = deviceToken!.count * MemoryLayout<Int16>.stride
        if length == 0 {
            return nil
        }
    
        var hexString = ""
        
        var iter = deviceToken!.makeIterator()
        
        while true {
                   guard
                       let char = iter.next()
                      
                       else {
                           break
                       }
            hexString += String(format: "%02x", char)
        }
        
        return hexString
    }
}





Push Notification device token from APNS auth response.

Alex Zavatone
 

Sometimes we want to get the string value of the device token after requesting push auth from APNS in didRegisterForRemoteNotificationWithDeviceToken.

Here’s how you can get that string value in Objective-C and Swift.

Cheers,
Alex Zavatone


//
//  APNSHelper.h
//  pushy
//
//  Created by Alex Zavatone on 3/10/21.
//  Copyright © 2021. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface APNSHelper : NSObject

+ (NSString *)stringFromDeviceToken:(NSData *)deviceToken;

@end

NS_ASSUME_NONNULL_END


//
//  APNSHelper.m
//  pushy
//
//  Created by Alex Zavatone on 3/10/21.
//  Copyright © 2021. All rights reserved.
//

#import "APNSHelper.h"

@implementation APNSHelper

+ (NSString *)stringFromDeviceToken:(NSData *)deviceToken
{
    NSUInteger length = deviceToken.length;
    if (length == 0) {
        return nil;
    }
    const unsigned char *buffer = deviceToken.bytes;
    NSMutableString *hexString  = [NSMutableString stringWithCapacity:(length * 2)];
    for (int charIndex = 0; charIndex < length; charIndex++) {
        [hexString appendFormat:@"%02x", buffer[charIndex]];
    }
    return [hexString copy];
}

@end




//
//  APNSHelperSwift.swift
//  pushy
//
//  Created by Alex Zavatone on 3/11/21.
//

import Foundation

@objc(APNSHelperSwift)
class APNSHelperSwift: NSObject
{

    

    @objc(stringFromDeviceToken:) public class func stringFromDeviceToken(deviceToken: Data?) -> String?
    {
        if (deviceToken == nil) {
            return nil;
        }

        

        let length = deviceToken!.count * MemoryLayout<Int16>.stride
        if length == 0 {
            return nil
        }

    

        var hexString = ""

        

        var iter = deviceToken!.makeIterator()

        

        while true {
                   guard
                       let char = iter.next()

                      

                       else {
                           break
                       }
            hexString += String(format: "%02x", char)
        }

        

        return hexString
    }
}




Re: window of document

Andy Lee
 

It looks like there is no public getter for the "window" IBOutlet, even though Interface Builder knows about it and even though there is a public *setter*.

You can get to your window by way of the document's "windowControllers" array. Unless you've overridden makeWindowControllers to do otherwise, it will contain just one NSWindowController, and you can ask it for its window. This worked for me in a scratch app I just created.

If windowControllers does have multiple elements, I think you'll need to add some way to figure out which is the one you want. But I've never had that situation, so maybe there is a better answer.

--Andy

On Mon, Feb 22, 2021, at 8:12 PM, James Walker wrote:
Say I create a new document-based Mac app in Xcode 12.4. In
Document.xib, I see that Document, the File’s Owner, has an outlet
“window”. But in the source code of the Document class, if I try to
refer to “self.window”, I get a compile error, “no getter method for
read from property”. I tried adding a property declaration for a
window IBOutlet property of Document, but then I got a weird situation
where the document creates an NSWindowController that does not own any
window. What’s going on? This is too basic, I’m sure that whatever
the answer is, it will make me slap my head and say “duh”.





window of document

James Walker
 

Say I create a new document-based Mac app in Xcode 12.4. In Document.xib, I see that Document, the File’s Owner, has an outlet “window”. But in the source code of the Document class, if I try to refer to “self.window”, I get a compile error, “no getter method for read from property”. I tried adding a property declaration for a window IBOutlet property of Document, but then I got a weird situation where the document creates an NSWindowController that does not own any window. What’s going on? This is too basic, I’m sure that whatever the answer is, it will make me slap my head and say “duh”.


NSImageView does not animate

Gerriet M. Denkmann
 

macOS 11.2.1

Some app which shows animated gifs, and which has been working just fine, now is not.

@IBOutlet var catImageView: NSImageView!

func applicationDidFinishLaunching(_ aNotification: Notification)
{
let image = NSImage.init(byReferencingFile: Bundle.main.path(forResource: "Sleeps", ofType: "gif")! )
catImageView.image = image
catImageView.animates = true
}

I see just one cycle of frames of the gif-sequence, then it stops moving.
The gif has two images which should keep alternating.

When I look at my gif in Xcode, it behaves absolutely normal.

What can I do to fix this?


Gerriet.


Re: Help with UTIs and UIDocumentPickerViewController

Rick Aurbach
 

Sorry, Alex.  As usual, publishing this allowed me to see my mistake.

First of all, the "msug" thing has to do with the output file, not the input file.

Secondly, the problem was in the code -- I was specifying public.comma-delimited-values-text, but it SHOULD have been public.comma-separated-values-text.

Sorry to waste your time.

Rick


Re: Help with UTIs and UIDocumentPickerViewController

Alex Zavatone
 

FYI, you might want to heck out the expected file types in UTTypes.h

It’s here.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Headers/UTType.h


Though this is for iOS, it might help.  Scroll down to "What is a Uniform Type Identifier?"


For a little backgorund info.

Below is this info.

init(forOpeningFilesWithContentTypes allowedContentTypes: [String]?)




Below that is this.

Greyed Out Icon: The Solution

//UIDocumentViewControllerlet utis = func getUTTypeCreateAllIdentifiers(for: "gpx")
let viewController = UIDocumentViewController(forOpeningFilesWithContentTypes: utis)
//UIDocumentPickerViewControllerlet viewController = UIDocumentPickerViewController(documentTypes: utis, in: .open)


I hope this helps.

Alex Zavatone



On Feb 9, 2021, at 3:50 PM, Alex Zavatone via groups.io <zav@...> wrote:

Is this the section where you are specifying the file type?

<key>public.filename-extension</key>
<array>
     <string>msug</string>
</array>
</dict>

Does that look correct for a CSV file?

Alex Zavatone


On Feb 9, 2021, at 3:43 PM, Rick Aurbach via groups.io <rlaurb@...> wrote:

I am writing a small utility app that reads CSV files, processes the contents, and outputs the result in a different format.

I want to use UIDocumentPickerViewController to select the file to be processed. (Appropriate code is below.) I load test data into the Simulator by drag-and-drop from my Mac to the Simulator's Files app. When I present the picker, it shows the files I added, but they are all in a disabled state and cannot be selected.

I assume that this is due to a problem with the UTIs in my info.plist file, but I don't know what I'm doing wrong. Can anyone help me?

Code:

lazy var inputPicker: UIDocumentPickerViewController = {

let picker: UIDocumentPickerViewController

if #available(iOS 14, *) {

guard let uttype = UTType("public.comma-delimited-values-text") else { fatalError() }

picker = UIDocumentPickerViewController(forOpeningContentTypes: [uttype])

} else {

picker = UIDocumentPickerViewController(documentTypes: ["public.comma-delimited-values-text"], in: .import)

}

picker.delegate = self

picker.allowsMultipleSelection = false

return picker

}()


chooseFile.onTap { btn in

self.present(self.inputPicker, animated: true, completion: nil)

}



From the Info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Comma-Delimited Text File</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Morning Sugar Import File</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.aurbach.morning-sugar-data</string>
</array>
</dict>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Morning Sugar Import File</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.aurbach.morning-sugar-data</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>msug</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Comma-Separated Values File </string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.comma-delimited-values-text</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>csv</string>
</array>
</dict>
</dict>
</array>

(note: Since this utility app does not originate the definition of either of these UTIs, I have specified UIImportedTypesDeclarations, but no UIExportedTypesDeclarations.)
 



Re: Help with UTIs and UIDocumentPickerViewController

Alex Zavatone
 

Is this the section where you are specifying the file type?

<key>public.filename-extension</key>
<array>
     <string>msug</string>
</array>
</dict>

Does that look correct for a CSV file?

Alex Zavatone


On Feb 9, 2021, at 3:43 PM, Rick Aurbach via groups.io <rlaurb@...> wrote:

I am writing a small utility app that reads CSV files, processes the contents, and outputs the result in a different format.

I want to use UIDocumentPickerViewController to select the file to be processed. (Appropriate code is below.) I load test data into the Simulator by drag-and-drop from my Mac to the Simulator's Files app. When I present the picker, it shows the files I added, but they are all in a disabled state and cannot be selected.

I assume that this is due to a problem with the UTIs in my info.plist file, but I don't know what I'm doing wrong. Can anyone help me?

Code:

lazy var inputPicker: UIDocumentPickerViewController = {

let picker: UIDocumentPickerViewController

if #available(iOS 14, *) {

guard let uttype = UTType("public.comma-delimited-values-text") else { fatalError() }

picker = UIDocumentPickerViewController(forOpeningContentTypes: [uttype])

} else {

picker = UIDocumentPickerViewController(documentTypes: ["public.comma-delimited-values-text"], in: .import)

}

picker.delegate = self

picker.allowsMultipleSelection = false

return picker

}()


chooseFile.onTap { btn in

self.present(self.inputPicker, animated: true, completion: nil)

}



From the Info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Comma-Delimited Text File</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Morning Sugar Import File</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.aurbach.morning-sugar-data</string>
</array>
</dict>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Morning Sugar Import File</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.aurbach.morning-sugar-data</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>msug</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Comma-Separated Values File </string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.comma-delimited-values-text</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>csv</string>
</array>
</dict>
</dict>
</array>

(note: Since this utility app does not originate the definition of either of these UTIs, I have specified UIImportedTypesDeclarations, but no UIExportedTypesDeclarations.)
 

61 - 80 of 1426