问题
I am trying to use https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5 to generate a global identifier. When I try the sample in git it works fine and displays an identifier correctly. But when I try to incorporate the files into a new project it does not work!
I have included -
#import "UIDevice+IdentifierAddition.h"
in my SampleAppDelegate.m, copy pasted all files in the project, and am using
NSString *di = [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier];
in the init method. I put a breakpoint on the first line of uniqueGlobalDeviceIdentifier method, but it is never reached! Am I missing something?
EDIT:
Exception -
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDevice uniqueGlobalDeviceIdentifier]: unrecognized selector sent to instance 0x68170c0'
回答1:
It looks like UIDevice+IdentifierAddition.m
is not being compiled. To check / add it:
- Click on the project in the navigator on the left in Xcode.
- Select the app target.
- Select the 'Build Phases' tab.
- Open up 'Compile Sources'.
- Check that
UIDevice+IdentifierAddition.m
is in there. If not, then click the '+', select it and click add.
The exception points to this as the fix because it's saying that there is no method on UIDevice
called uniqueGlobalDeviceIdentifier
, which is added by the category.
来源:https://stackoverflow.com/questions/9897162/ios-uuid-generation-throwing-a-strange-exception