Re: [问题] iOS notification

楼主: trleee (小孟)   2014-12-12 15:16:36
您好 我之前也有做推播的处理
不过我用的是
- (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显示推播讯息 如果有动作也要询问使用者 不然会被吓到
作者: valda (valda)   2014-12-12 17:41:00
感激~非常受用~

Links booklink

Contact Us: admin [ a t ] ucptt.com