Skip to content

Commit

Permalink
[foundation] Fix inlined 'NSUserActivity (IntentsAdditions)' to work …
Browse files Browse the repository at this point in the history
…if nothing else from Intents is used. Fixes #4894 (#4974)

The selectors `suggestedInvocationPhrase` and `setSuggestedInvocationPhrase`
needs Intents.framework to be loaded into memory. Otherwise an exception
occurs:

```
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[NSUserActivity setSuggestedInvocationPhrase:]: unrecognized selector sent to instance 0x19cb3f00
```

When the linker is enabled there's no clue (e.g. namespaces from
preserved types) that `Intents` is required to call the property.

The fix is to provide an hint that will force the linker to keep a type
(a small enum available in all platforms in this case) which tells
`mtouch` (based on the type's namespace) to instruct the native linker
(Apple's `ld`) to [weak]link the Intents.framework in the application
executable.

Note: other selections from the category works fine.

reference:
#4894
  • Loading branch information
spouliot authored Oct 12, 2018
1 parent 40288e4 commit f4dbb68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5209,7 +5209,16 @@ partial interface NSUserActivity {

[Watch (5,0), NoTV, NoMac, iOS (12,0)]
[NullAllowed, Export ("suggestedInvocationPhrase")]
string SuggestedInvocationPhrase { get; set; }
string SuggestedInvocationPhrase {
// This _simply_ ensure that the Intents namespace (via the enum) will be present which,
// in turns, means that the Intents.framework is loaded into memory and this makes the
// selectors (getter and setter) work at runtime. Other selectors do not need it.
// reference: https://github.com/xamarin/xamarin-macios/issues/4894
[PreSnippet ("GC.KeepAlive (Intents.INCallCapabilityOptions.AudioCall); // no-op to ensure Intents.framework is loaded into memory")]
get;
[PreSnippet ("GC.KeepAlive (Intents.INCallCapabilityOptions.AudioCall); // no-op to ensure Intents.framework is loaded into memory")]
set;
}

[Watch (5, 0), NoTV, NoMac, iOS (12, 0)]
[Export ("eligibleForPrediction")]
Expand Down

1 comment on commit f4dbb68

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Running XM tests on '10.13', Test docs' 🔥 : hudson.AbortException: Xamarin.Mac tests on macOS 10.13 failed (xammac_tests)

Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)
🔥 Xamarin.Mac tests on macOS 10.13 failed (xammac_tests) 🔥
Test run succeeded

Please sign in to comment.