Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hyukhur/7480160 to your computer and use it in GitHub Desktop.
Save hyukhur/7480160 to your computer and use it in GitHub Desktop.
아이폰 개발 중 시뮬레이터에 푸시 전달받아 앱 런칭되는 것을 흉내내야하는 경우가 발생하는데 이 때 사용하면 된다. 스키마 설정에 들어가보면 인자값 설정하는 부분이 있고 -option 이라는 값으로 NSPropertyList 값( apn을 통해 앱으로 전달 받는 포맷)을 그대로 전달해주면 된다.
- (BOOL)application:(UIApplication *)aApplication didFinishLaunchingWithOptions:(NSDictionary *)aLaunchOptions
{
/* for Push Notification in Simulator */
#if TARGET_IPHONE_SIMULATOR
NSProcessInfo *sProcessInfo = [NSProcessInfo processInfo];
NSArray *sArguments = [sProcessInfo arguments];
NSUInteger sIndex = [sArguments indexOfObject:@"-option"];
NSString *sPropertyFomatString = [sArguments objectAtIndexOrNil:sIndex+1];
/* format으로 NULL을 전달하면 앱크래시 */
NSPropertyListFormat sPlistFormat;
NSError *sError = nil;
aLaunchOptions = [NSPropertyListSerialization propertyList:sPropertyFomatString isValidForFormat:0] ? [NSPropertyListSerialization propertyListWithData:[sPropertyFomatString dataUsingEncoding:NSUTF8StringEncoding] options:0 format:&sPlistFormat error:&sError] : [sPropertyFomatString JSONDecode];
if (sError)
{
DDLogError(@"option parse error: %@", sError);
}
#endif
}
/*
arguments passed on launch with '-option'
-option '{
UIApplicationLaunchOptionsRemoteNotificationKey = {
aps = {
alert = {
"loc-args" = ();
"loc-key" = "";
};
badge = 2;
sound = "";
};
};
}'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment