Re: [問題] iOS notification

看板MacDev作者 (小孟)時間10年前 (2014/12/12 15:16), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串4/4 (看更多)
您好 我之前也有做推播的處理 不過我用的是 - (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://www.ptt.cc/bbs/MacDev/M.1418368598.A.A8E.html

12/12 17:41, , 1F
感激~非常受用~
12/12 17:41, 1F
文章代碼(AID): #1KYfPMgE (MacDev)
文章代碼(AID): #1KYfPMgE (MacDev)