作者trleee (小孟)
看板MacDev
标题Re: [问题] iOS notification
时间Fri Dec 12 15:16:36 2014
您好 我之前也有做推播的处理
不过我用的是
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
而你用的是
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
不确定是不是这原因执行两次 你用的这方法只能在 iOS 7 以上使用
另外你少考虑一种情况 就是当他没有执行App点选推播後的情况
didFinishLaunchingWithOptions 方法请加上这段
NSDictionary *message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([message objectForKey:@"storeID"] && ![[message objectForKey:@"storeID"] isEqualToString:@""]) {
[self performSelectorOnMainThread:@selector(goStore:) withObject:message waitUntilDone:NO];
}
didReceiveRemoteNotification 我是简单这样写
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) { //前景
UIAlertView *alertView;
if ([userInfo objectForKey:@"storeID"] && ![[userInfo objectForKey:@"storeID"] isEqualToString:@""]) {
alertView = [[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"开启连结", nil];
alertView.tag = 1;
}
[alertView show];
}else { //背景
if ([userInfo objectForKey:@"storeID"] && ![[userInfo objectForKey:@"storeID"] isEqualToString:@""]) {
[self performSelectorOnMainThread:@selector(goStore:) withObject:pushNotification waitUntilDone:NO];
}
}
这样你发推播的payload时就可以自创一些值来做动作
例如 跳网页 跳appstore 跳该app的某各项目页 等等
而且在前景收到推播你最好先alertView显示推播讯息 如果有动作也要询问使用者 不然会被吓到
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.199.198.59
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1418368598.A.A8E.html
1F:推 valda: 感激~非常受用~ 12/12 17:41